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;
const int N = 110;
const int oo = 2e9;
int n, m, ans = oo, sx, sy;
string pat = "ENSW";
char s[N][N], let = 'a';
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
cin >> s[i][j];
if (s[i][j] == 'o'){
sx = i;
sy = j;
}
}
for (int it = 0; it < 4; it++){
int cx = sx, cy = sy, len = 1;
if (it == 0)
cy++;
else if (it == 1)
cx--;
else if (it == 2)
cx++;
else cy--;
while (1){
if (s[cx][cy] == '.') break;
if (s[cx][cy] == 'x') {
if (len < ans){
ans = len;
let = pat[it];
}
break;
}
len++;
if (s[cx][cy] == '^')
cx--;
else if (s[cx][cy] == 'v')
cx++;
else if (s[cx][cy] == '>')
cy++;
else cy--;
}
}
if (ans == oo)
cout << ":(";
else cout << ":)\n" << let;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |