#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
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;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
324 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |