#include <bits/stdc++.h>
using namespace std;
char grid[100][100];
int n, m, sx, sy, dx, dy;
int is_good(int x, int y) {
int cnt = 0;
while (1) {
if (grid[x][y] == '.' || grid[x][y] == 'o') return INT_MAX;
else if (grid[x][y] == 'x') return cnt;
else if (grid[x][y] == '^') x--;
else if (grid[x][y] == 'v') x++;
else if (grid[x][y] == '<') y--;
else if (grid[x][y] == '>') y++;
cnt++;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {
cin >> grid[i][j];
if (grid[i][j] == 'o') sx = i, sy = j;
if (grid[i][j] == 'x') dx = i, dy = j;
}
pair<int, string> ans = {INT_MAX - 1, ":(\n"};
ans = min(ans, {is_good(sx + 1, sy), ":)\nS\n"});
ans = min(ans, {is_good(sx - 1, sy), ":)\nN\n"});
ans = min(ans, {is_good(sx, sy + 1), ":)\nE\n"});
ans = min(ans, {is_good(sx, sy - 1), ":)\nW\n"});
cout << ans.second;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
404 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
0 ms |
364 KB |
Output is correct |