#include <bits/stdc++.h>
using namespace std;
int n,m;
vector<string>v;
map<pair<int,int>,int64_t>mp;
int64_t dfs(int i, int j) {
if(v[i][j] == 'x') return 0;
if(v[i][j] == '.') return INT_MAX;
if(mp.count({i,j})) return mp[{i,j}];
if(v[i][j] == 'v') return mp[{i,j}] = 1 + dfs(i+1,j);
else if(v[i][j] == '^') return mp[{i,j}] = 1 + dfs(i-1,j);
else if(v[i][j] == '>') return mp[{i,j}] = 1 + dfs(i,j+1);
else return mp[{i,j}] = 1 + dfs(i,j-1);
}
signed main() {
cin>>n>>m;
v.resize(n);
for(auto &z : v) cin>>z;
pair<int,int>s;
for(int i = 0 ; i < n ; i++) {
for(int j = 0 ; j < m ; j++) {
if(v[i][j] == 'o') s.first=i,s.second=j;
}
}
char win;
int64_t best = INT_MAX, ans;
ans=dfs(s.first,s.second+1);
if(ans < best) {
win = 'E',best=ans;
}
ans=dfs(s.first-1,s.second);
if(ans < best) {
win = 'N',best=ans;
}
ans=dfs(s.first+1,s.second);
if(ans < best) {
win = 'S',best=ans;
}
ans=dfs(s.first,s.second-1);
if(ans < best) {
win = 'W',best=ans;
}
if(best < INT_MAX) cout << ":)\n" << win;
else cout << ":(";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Runtime error |
306 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Runtime error |
293 ms |
524292 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |