#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 5, INF = 1e9 + 5;
int n, m, ans = INF + 1, x, y, dist;
char c = 'Z', arr[N][N];
int dfs(int x, int y){
if(arr[x][y] == 'x') return 0;
else{
if(arr[x][y] == '^') return min(dfs(x - 1, y) + 1, INF);
else if(arr[x][y] == '>') return min(dfs(x, y + 1) + 1, INF);
else if(arr[x][y] == '<') return min(dfs(x, y - 1) + 1, INF);
else if(arr[x][y] == 'v') return min(dfs(x + 1, y) + 1, INF);
else return INF;
}
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> n >> m;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> arr[i][j];
if(arr[i][j] == 'o') x = i, y = j;
}
}
if((dist = dfs(x - 1, y)) <= ans) c = (dist == ans ? min(c, 'N') : 'N'), ans = dist;
if((dist = dfs(x, y + 1)) <= ans) c = (dist == ans ? min(c, 'E') : 'E'), ans = dist;
if((dist = dfs(x, y - 1)) <= ans) c = (dist == ans ? min(c, 'W') : 'W'), ans = dist;
if((dist = dfs(x + 1, y)) <= ans) c = (dist == ans ? min(c, 'S') : 'S'), ans = dist;
if(ans == INF) cout << ":(";
else cout << ":)\n" << c;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
312 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
312 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
316 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
312 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |