#include <bits/stdc++.h>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
using namespace std;
const int man = (int)(1e3);
const int steps[4][2] = {{0, +1}, {-1, 0}, {+1, 0}, {0, -1}};
int n, m, res, ps, sx, sy;
int a[man][man];
bool mk[man][man];
void rec(int x, int y, int fx, int cur) {
if (a[x][y] == -1) {
return;
}
if (mk[x][y] == true) {
return;
}
if (a[x][y] == 4) {
if ((ps == -1) || (cur < res)) {
res = cur;
ps = fx;
}
return;
}
mk[x][y] = true;
rec(x + steps[a[x][y]][0], y + steps[a[x][y]][1], fx, cur + 1);
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef _LOCAL
in("inA.txt");
out("outA.txt");
#endif
string t = "ENSW";
cin >> n >> m;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
char c;
cin >> c;
if (c == 'o') {
sx = i, sy = j;
}
if ((c == 'o') || (c == '.')) {
a[i][j] = -1;
}
if (c == 'x') {
a[i][j] = 4;
}
if (c == '<') {
a[i][j] = 3;
}
if (c == '^') {
a[i][j] = 1;
}
if (c == '>') {
a[i][j] = 0;
}
if (c == 'v') {
a[i][j] = 2;
}
}
}
ps = -1;
for (int i = 0; i < 4; ++i) {
rec(sx + steps[i][0], sy + steps[i][1], i, 0);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
mk[i][j] = 0;
}
}
}
if (ps != -1) {
cout << ":)\n" << t[ps] << "\n";
} else {
cout << ":(";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
768 KB |
Output is correct |
4 |
Correct |
1 ms |
876 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
620 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
620 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
620 KB |
Output is correct |
5 |
Correct |
1 ms |
748 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
620 KB |
Output is correct |
8 |
Correct |
1 ms |
748 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
876 KB |
Output is correct |
11 |
Correct |
1 ms |
640 KB |
Output is correct |
12 |
Correct |
1 ms |
748 KB |
Output is correct |
13 |
Correct |
1 ms |
748 KB |
Output is correct |
14 |
Correct |
1 ms |
620 KB |
Output is correct |
15 |
Correct |
1 ms |
620 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
364 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |