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;
typedef long long ll;
#define endl '\n'
vector<string> v;
int calc(int i,int j){
if(v[i][j] == '.') 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 (stderr)
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;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |