#include "bits/stdc++.h"
using namespace std;
int main() {
int r, m;
cin >> r >> m;
vector<vector<char>> gr(r, vector<char>(m));
int a, b;
int c, d;
for (int i = 0; i < r; i ++) {
for (int j = 0; j < m; j ++) {
cin >> gr[i][j];
if ('o' == gr[i][j]) {
a = i;
b = j;
}
if ('x' == gr[i][j]) {
c = i;
d = j;
}
}
}
int maxr = 1e9;
int an = maxr;
char sy = 'Z';
function<void(int,int,int,char)> dfs;
dfs = [&](int y, int x, int s, char l){
if (y == c && x == d) {
if (s < an) {
an = s;
sy = l;
} else if (s == an) {
sy = min(sy, l);
}
} else if ('>' == gr[y][x]) {
dfs(y, x + 1, s + 1, l);
} else if ('<' == gr[y][x]) {
dfs(y, x - 1, s + 1, l);
} else if ('v' == gr[y][x]) {
dfs(y + 1, x, s + 1, l);
} else if ('^' == gr[y][x]) {
dfs(y - 1, x, s + 1, l);
}
};
if (0 < b) {
dfs(a, b - 1, 1, 'W');
}
if (b + 1 < m) {
dfs(a, b + 1, 1, 'E');
}
if (0 < a) {
dfs(a - 1, b, 1, 'N');
}
if (a + 1 < r) {
dfs(a + 1, b, 1, 'S');
}
if (maxr != an) {
cout << ":)\n" << sy << '\n';
} else {
cout << ":(\n";
}
}
Compilation message
patkice.cpp: In function 'int main()':
patkice.cpp:55:12: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
55 | dfs(a, b - 1, 1, 'W');
| ~~~^~~~~~~~~~~~~~~~~~
patkice.cpp:61:12: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
61 | dfs(a - 1, b, 1, 'N');
| ~~~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
504 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |