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;
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 != 0) {
int a = rec(o-1, 0);
if (a < m) {
m = a;
d = ":)\nW";
}
}
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";
}
}
cout << d << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |