#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 < a) {
dfs(a, b - 1, 1, 'W');
}
if (a + 1 < m) {
dfs(a, b + 1, 1, 'E');
}
if (0 < b) {
dfs(a - 1, b, 1, 'N');
}
if (b + 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:61:12: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
61 | dfs(a - 1, b, 1, 'N');
| ~~~^~~~~~~~~~~~~~~~~~
patkice.cpp:55:12: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
55 | dfs(a, b - 1, 1, 'W');
| ~~~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
504 KB |
Output is correct |
9 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |