This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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';
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |