#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
vector<string> v;
int calc(int i,int j){
if(v[i][j] == '.' || v[i][j] == 'o') return 1e9;
if(v[i][j] == 'x') return 0;
if(v[i][j] == '>') return calc(i,j+1) + 1;
if(v[i][j] == '<') return calc(i,j-1) + 1;
if(v[i][j] == 'v') return calc(i+1,j) + 1;
return calc(i-1,j) + 1;
}
void solve(){
int n,m;
cin>>n>>m;
v.resize(n);
for(auto &i:v) cin>>i;
pair<int,int> start;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(v[i][j] == 'o') start = {i,j};
}
}
auto [x,y] = start;
// R -> E
// U -> N
// D -> S
// L -> W
vector<int> ans = {calc(x,y+1),calc(x-1,y),calc(x+1,y),calc(x,y-1)};
string dir = "ENSW";
int anss = *min_element(ans.begin(),ans.end());
if(anss >= 1e9) cout<<":("<<endl;
else {
cout<<":)"<<endl;
for(int i=0;i<4;i++){
if(ans[i] == anss) return cout<<dir[i]<<endl, void();
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
}
Compilation message
patkice.cpp: In function 'void solve()':
patkice.cpp:25:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
25 | auto [x,y] = start;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
360 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
404 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |