#include<bits/stdc++.h>
using namespace std;
char a[101][101];
const int M=101;
pair<char,int> calc(int x,int y){
pair<char,int> ans;
if(a[x][y]=='^') ans=calc(x-1,y);
else if(a[x][y]=='>') ans=calc(x,y+1);
else if(a[x][y]=='<') ans=calc(x,y-1);
else if(a[x][y]=='v') ans=calc(x+1,y);
else return {a[x][y],0};
ans.second++;
return ans;
}
int main(){
int n,m;
cin>>n>>m;
int sti,stj;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
if(a[i][j]=='o') sti=i,stj=j;
}
}
int px[4]={0,-1,1,0},py[4]={1,0,0,-1};
string dir="ENSW";
int mn=M*M;
char ans;
for(int d=0;d<4;d++){
int ci=sti+px[d],cj=stj+py[d];
auto x=calc(ci,cj);
if(x.first=='x'){
if(mn>x.second) mn=x.second,ans=dir[d];
}
}
if(mn<M+M){
cout<<":)"<<endl;
cout<<ans<<endl;
}
else cout<<":(";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |