#include<bits/stdc++.h>
using namespace std;
#define Study ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define pb push_back
#define ff first
#define ss second
#define ins insert
#define all(x) x.begin(),x.end()
#define fori(x,y,z) for(ll x=y;x<=z;x++)
const ll INF=1e9;
const ll sz=1e2+10;
const ll mod=1e9+7;
vector<vector<char>>c(sz,vector<char>(sz,0));
ll dfs(ll x,ll y,ll cr){
if(c[x][y]=='.' || c[x][y]=='o'){
return INF;
}
if(c[x][y]=='x'){
return cr;
}
if(c[x][y]=='<'){
return dfs(x,y-1,cr+1);
}
else if(c[x][y]=='^'){
return dfs(x-1,y,cr+1);
}
else if(c[x][y]=='>'){
return dfs(x,y+1,cr+1);
}
else{
return dfs(x+1,y,cr+1);
}
}
void work(){
ll n,m;
cin>>n>>m;
ll x,y;
fori(i,1,n){
string s;
cin>>s;
fori(j,0,m-1){
c[i][j+1]=s[j];
if(c[i][j+1]=='o'){
x=i;y=j+1;
}
}
}
ll ans=INF;
char node;
ll cr=dfs(x,y+1,0);
if(cr<ans){
ans=cr;
node='E';
}
cr=dfs(x-1,y,0);
if(cr<ans){
ans=cr;
node='N';
}
cr=dfs(x+1,y,0);
if(cr<ans){
ans=cr;
node='S';
}
cr=dfs(x,y-1,0);
if(cr<ans){
ans=cr;
node='W';
}
if(ans<INF){
cout<<":)\n"<<node;
}
else
cout<<":(";
}
int main(){
Study;
ll t=1;
//cin>>t;
while(t--){
work();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |