#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;
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<m; j++) grid[i][j] = mp[s[j]];
}
for(int i = 0; i<n; i++){
for(int j = 0; j<m; j++){
if(grid[i][j] != array<int, 2>{-INF, -INF}) continue;
ans = min(ans, {dfs(i+1, j), 'S'});
ans = min(ans, {dfs(i-1, j), 'N'});
ans = min(ans, {dfs(i, j+1), 'E'});
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 |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |