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;
#define MAXN 105
#define INF 1000000009
int n, m;
array<int, 2> grid[MAXN][MAXN];
map<char, array<int, 2>> mp;
bool vis[MAXN][MAXN];
pair<int, char> ans = {INF, 'a'};
int dfs(int x, int y){
if(grid[x][y] == array<int, 2>{0, 0} || grid[x][y] == array<int, 2>{-INF, -INF}) return INF;
if(grid[x][y] == array<int, 2>{INF, INF}) return 0;
return dfs(x+grid[x][y][0], y+grid[x][y][1])+1;
}
int main(){
// freopen("a.in", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
mp['^'] = {-1, 0}; mp['v'] = {1, 0}; mp['<'] = {0, -1}; mp['>'] = {0, 1}; mp['o'] = {-INF, -INF}; mp['.'] = {0, 0}; mp['x'] = {INF, INF};
for(int i = 0; i<n; i++){
string s; cin >> s;
for(int j = 0; j<n; j++) grid[i][j] = mp[s[j]];
}
for(int i = 0; i<n; i++){
for(int j = 0; j<n; j++){
if(grid[i][j] != array<int, 2>{-INF, -INF}) continue;
memset(vis, 0, sizeof vis);
ans = min(ans, {dfs(i+1, j), 'S'});
memset(vis, 0, sizeof vis);
ans = min(ans, {dfs(i-1, j), 'N'});
memset(vis, 0, sizeof vis);
ans = min(ans, {dfs(i, j+1), 'E'});
memset(vis, 0, sizeof vis);
ans = min(ans, {dfs(i, j-1), 'W'});
}
}
if(ans.first == INF){
cout << ":(" << endl;
}
else{
cout << ":)" << endl;
cout << ans.second << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |