#include<bits/stdc++.h>
using namespace std;
int r, s;
vector<vector<int>> distance;
vector<string> sea;
int dfs(int x, int y){
if(x >= r or y >= s) return 1e9;
if(x < 0 or y < 0) return 1e9;
if(sea[x][y] == '.') return 1e9;
if(sea[x][y] == '^') return 1+dfs(x-1, y);
if(sea[x][y] == 'x') return 0;
if(sea[x][y] == '<') return 1+dfs(x, y-1);
if(sea[x][y] == '>') return 1+dfs(x, y+1);
if(sea[x][y] == 'v') return 1+dfs(x+1, y);
}
int main(){
cin >> r >> s;
pair<int, int> start;
sea = vector<string>(r);
for(int i = 0; i < r; ++i) {
cin >> sea[i];
for(int j = 0; j < s; ++j){
if(sea[i][j] == 'o') start = {i, j};
}
}
int bestDistance = 1e9;
char directionBest = '-';
int east = dfs(start.first, start.second+1);
if(east < bestDistance){
bestDistance = east;
directionBest = 'E';
}
int north = dfs(start.first-1, start.second);
if(north < bestDistance){
bestDistance = north;
directionBest = 'N';
}
int south = dfs(start.first +1, start.second);
if(south < bestDistance){
bestDistance = south;
directionBest = 'S';
}
int west = dfs(start.first, start.second-1);
if(west < bestDistance){
bestDistance = west;
directionBest = 'W';
}
if(bestDistance == 1e9) cout << ":(" << endl;
else{
cout << ":)" << endl;
cout << directionBest << endl;
}
return 0;
}
Compilation message
patkice.cpp: In function 'int dfs(int, int)':
patkice.cpp:18:1: warning: control reaches end of non-void function [-Wreturn-type]
18 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1045 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1076 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |