#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 -1;
if (map[i][j]=='x') return 0;
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;
}
Compilation message
patkice.cpp: In function 'int direction(int, int, std::vector<std::vector<char> >&)':
patkice.cpp:8:9: warning: unused variable 'ans' [-Wunused-variable]
8 | int ans=0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
312 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
266 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |