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 <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 | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |