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;
char grid[100][100];
int n, m, sx, sy, dx, dy;
int is_good(int x, int y) {
int cnt = 0;
while (1) {
if (x == -1 || y == -1 || x == n || y == n) 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++;
else return INT_MAX;
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, ":("};
ans = min(ans, {is_good(sx + 1, sy), ":)\nS"});
ans = min(ans, {is_good(sx - 1, sy), ":)\nN"});
ans = min(ans, {is_good(sx, sy + 1), ":)\nE"});
ans = min(ans, {is_good(sx, sy - 1), ":)\nW"});
cout << ans.second;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |