#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 5, INF = 1e9 + 5;
int n, m, ans = INF, x, y, dist;
char c, 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), INF);
else if(arr[x][y] == '>') return min(dfs(x, y + 1), INF);
else if(arr[x][y] == '<') return min(dfs(x, y - 1), INF);
else if(arr[x][y] == 'v') return min(dfs(x + 1, y), 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) ans = dist, c = 'N';
if(dist = dfs(x, y + 1) < ans) ans = dist, c = 'E';
if(dist = dfs(x, y - 1) < ans) ans = dist, c = 'W';
if(dist = dfs(x + 1, y) < ans) ans = dist, c = 'S';
if(ans == INF) cout << ":(";
else cout << ":)\n" << c;
}
Compilation message
patkice.cpp: In function 'int main()':
patkice.cpp:35:13: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
35 | if(dist = dfs(x - 1, y) < ans) ans = dist, c = 'N';
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
patkice.cpp:36:13: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
36 | if(dist = dfs(x, y + 1) < ans) ans = dist, c = 'E';
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
patkice.cpp:37:13: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
37 | if(dist = dfs(x, y - 1) < ans) ans = dist, c = 'W';
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
patkice.cpp:38:13: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
38 | if(dist = dfs(x + 1, y) < ans) ans = dist, c = 'S';
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |