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;
#define int long long
const int INF = 1e18;
void solve(){
int n, m; cin >> n >> m;
vector<vector<char>> a(n, vector<char>(m));
int sx, sy;
for(int i=0; i<n; i++)
for(int j=0; j<m; j++){
cin >> a[i][j];
if(a[i][j] == 'o')
sx = i, sy = j;
}
char ans; int dist = INF;
function<void(int, int, int, char)> dfs = [&](int x, int y, int d, char c){
if(a[x][y] == 'o' || a[x][y] == '.') return;
if(a[x][y] == 'x'){
if(d < dist || (d == dist && c < ans)){
ans = c;
dist = d;
}
}
if(a[x][y] == '>') dfs(x, y+1, d+1, c);
if(a[x][y] == '<') dfs(x, y-1, d+1, c);
if(a[x][y] == 'v') dfs(x+1, y, d+1, c);
if(a[x][y] == '^') dfs(x-1, y, d+1, c);
};
dfs(sx-1, sy, 1, 'N');
dfs(sx, sy+1, 1, 'E');
dfs(sx+1, sy, 1, 'S');
dfs(sx, sy-1, 1, 'W');
if(dist == INF) cout << ":(\n";
else cout << ":)\n" << ans << "\n";
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
solve();
return 0;
}
Compilation message (stderr)
patkice.cpp: In function 'void solve()':
patkice.cpp:37:8: warning: 'sy' may be used uninitialized in this function [-Wmaybe-uninitialized]
37 | dfs(sx, sy-1, 1, 'W');
| ~~~^~~~~~~~~~~~~~~~~~
patkice.cpp:11:9: warning: 'sx' may be used uninitialized in this function [-Wmaybe-uninitialized]
11 | int sx, sy;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |