#include<bits/stdc++.h>
using namespace std;
int r, s;
vector<vector<int>> distance;
vector<string> sea;
int dfs(int x, int y){
if(x >= r or y >= s) return 1e9;
if(x < 0 or y < 0) return 1e9;
if(sea[x][y] == '.') return 1e9;
if(sea[x][y] == '^') return 1+dfs(x-1, y);
if(sea[x][y] == 'x') return 0;
if(sea[x][y] == '<') return 1+dfs(x, y-1);
if(sea[x][y] == '>') return 1+dfs(x, y+1);
if(sea[x][y] == 'v') return 1+dfs(x+1, y);
return 1e9;
}
int main(){
cin >> r >> s;
pair<int, int> start;
sea = vector<string>(r);
for(int i = 0; i < r; ++i) {
cin >> sea[i];
for(int j = 0; j < s; ++j){
if(sea[i][j] == 'o') start = {i, j};
}
}
int bestDistance = 1e9;
char directionBest = '-';
int east = dfs(start.first, start.second+1);
if(east < bestDistance){
bestDistance = east;
directionBest = 'E';
}
int north = dfs(start.first-1, start.second);
if(north < bestDistance){
bestDistance = north;
directionBest = 'N';
}
int south = dfs(start.first +1, start.second);
if(south < bestDistance){
bestDistance = south;
directionBest = 'S';
}
int west = dfs(start.first, start.second-1);
if(west < bestDistance){
bestDistance = west;
directionBest = 'W';
}
if(bestDistance == 1e9) cout << ":(" << endl;
else{
cout << ":)" << endl;
cout << directionBest << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |