#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define endl '\n'
const ll MOD = 1e9+7;
const ll INF = 1e16;
const ll MAX = 2 * 1e5;
int n,m;
char arr[101][101];
int DFS(int x, int y){
if(arr[x][y] == 'o' || arr[x][y] == '.') return -1e8;
if(arr[x][y] == 'x') return 0;
if(arr[x][y] == '>') return DFS(x, y+1) + 1;
if(arr[x][y] == '<') return DFS(x, y-1) + 1;
if(arr[x][y] == 'v') return DFS(x + 1, y) + 1;
return DFS(x - 1, y) + 1;
}
void solve(){
cin>>n>>m;
pair<int,int> start;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin>>arr[i][j];
if(arr[i][j] == 'o') start = {i,j};
}
}
vector<pair<int, char>> ans;
int temp = DFS(start.first, start.second + 1);
if(temp >= 0)
ans.push_back({temp, 'E'});
temp = DFS(start.first, start.second - 1);
if(temp >= 0)
ans.push_back({temp, 'W'});
temp = DFS(start.first - 1, start.second);
if(temp >= 0)
ans.push_back({temp, 'N'});
temp = DFS(start.first + 1, start.second);
if(temp >= 0)
ans.push_back({temp, 'S'});
if(ans.size() == 0){
cout<<":(";
}else{
sort(ans.begin(), ans.end());
cout<<":)"<<endl;
cout<<ans[0].second;
}
}
int main()
{
cin.tie(NULL);
ios::sync_with_stdio(NULL);
int t = 1;
//cin>>t;
int temp = t;
while(t--){
//cout<<"Case #"<<temp - t<<" > "<<endl;
solve();
cout<<endl;
}
cout.flush();
}
Compilation message
patkice.cpp: In function 'int main()':
patkice.cpp:76:9: warning: unused variable 'temp' [-Wunused-variable]
76 | int temp = t;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 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 |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
328 KB |
Output is correct |
17 |
Correct |
1 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 |