#include <iostream>
using namespace std;
char a[105][105];
int m, n, u, v, res;
bool check;
void f(int x, int y) {
++res;
if(a[x][y] == '.') return;
if(a[x][y] == 'x') {check = 1; return;}
if(a[x][y] == 'v') f(x + 1, y);
if(a[x][y] == '^') f(x - 1, y);
if(a[x][y] == '<') f(x, y - 1);
if(a[x][y] == '>') f(x, y + 1);
}
int main()
{
ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
cin >> m >> n;
for(int i = 1; i <= m; ++i) {
for(int j = 1; j <= n; ++j) {
cin >> a[i][j];
if(a[i][j] == 'o') {
u = i;
v = j;
}
}
}
res = 0;
int ans = 1e9;
char k = 'a';
f(u, v + 1);
if(check && ans > res) {ans = res; k = 'E';}
res = 0; check = 0;
f(u - 1, v);
if(check && ans > res) {ans = res; k = 'N';}
res = 0; check = 0;
f(u + 1, v);
if(check && ans > res) {ans = res; k = 'S';}
res = 0; check = 0;
f(u, v - 1);
if(check && ans > res) {ans = res; k = 'W';}
if(ans == 1e9) cout << ":(";
else cout << ":)" << '\n' << k;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
280 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
312 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |