#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
vvi g;
int dest = 0, o = 0;
int rec(int n, int r) {
if (n == dest) return r;
for (int i: g[n]) return rec(i, r+1);
return 1e9+1;
}
int main() {
int r, s;
cin >> r >> s;
g = vvi(r*s, vi());
for (int i = 0; i < r*s; i++) {
char c;
cin >> c;
if (c == '<') g[i].push_back(i-1);
else if (c == '>') g[i].push_back(i+1);
else if (c == '^') g[i].push_back(i-s);
else if (c == 'v') g[i].push_back(i+s);
else if (c == 'o') o = i;
else if (c == 'x') dest = i;
}
int m = 1e9-1;
string d = ":(";
if (o % s != s-1) {
int a = rec(o+1, 0);
if (a < m) {
m = a;
d = ":)\nE";
}
}
if (o - s >= 0) {
int a = rec(o-s, 0);
if (a < m) {
m = a;
d = ":)\nN";
}
}
if (o + s < r*s) {
int a = rec(o+s, 0);
if (a < m) {
m = a;
d = ":)\nS";
}
}
if (o % s != 0) {
int a = rec(o-1, 0);
if (a < m) {
m = a;
d = ":)\nW";
}
}
cout << d << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 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 |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |