Submission #741707

# Submission time Handle Problem Language Result Execution time Memory
741707 2023-05-14T16:00:14 Z lalig777 Patkice (COCI20_patkice) C++14
0 / 50
256 ms 524288 KB
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int direction(int i, int j, vector<vector<char>>&map){
    int ans=0;
    if (map[i][j]=='.') return ans-1;
    if (map[i][j]=='x') return ans;
    if (map[i][j]=='>'){
        int ans=direction(i, j+1, map);
        if (ans==-1) return -1;
        else return 1+ans;
    }if (map[i][j]=='<'){
        int ans=direction(i, j-1, map);
        if (ans==-1) return -1;
        else return 1+ans;
    }if (map[i][j]=='^'){
        int ans=direction(i-1, j, map);
        if (ans==-1) return -1;
        else return 1+ans;
    }else{
        int ans=direction(i+1, j, map);
        if (ans==-1) return -1;
        else return 1+ans;
    }
}

int main(){
    int r, c;
    cin>>r>>c;
    pair<int,int>start;
    vector<vector<char>>map(r, vector<char>(c));
    for (int i=0; i<r; i++){
        for (int j=0; j<c; j++){
            cin>>map[i][j];
            if (map[i][j]=='o'){
                start.first=i;
                start.second=j;
            }
        }
    }int E=-1, N=-1, S=-1, W=-1;
    if (start.first!=r-1) N=direction(start.first-1, start.second, map);
    if (start.first!=0) S=direction(start.first+1, start.second, map);
    if (start.second!=r-1) E=direction(start.first, start.second+1, map);
    if (start.second!=0) W=direction(start.first, start.second-1, map);
    if (E==-1 and N==-1 and S==-1 and W==-1) cout<<":("<<endl;
    else{
        cout<<":)"<<endl;
        if (E!=-1 and (E<=N or N==-1) and (E<=S or S==-1) and (E<=W or W==-1)) cout<<"E"<<endl;
        else if (N!=-1 and (N<=E or E==-1) and (N<=S or S==-1) and (N<=W or W==-1)) cout<<"N"<<endl;
        else if (S!=-1 and (S<=E or E==-1) and (S<=N or N==-1) and (S<=W or W==-1)) cout<<"S"<<endl;
        else cout<<"W"<<endl;
    }return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 255 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 256 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -