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>
#define all(s) s.begin(),s.end()
#define F first
#define S second
using namespace std;
typedef int ll;
ll n,m,x,y;
char c[109][109];
pair<ll,char>ans;
ll go(ll i,ll j)
{
if(c[i][j]=='x')
return 0;
if(c[i][j]=='.'||c[i][j]=='o')
return 1e9;
if(c[i][j]=='>')
return go(i,j+1)+1;
if(c[i][j]=='<')
return go(i,j-1)+1;
if(c[i][j]=='^')
return go(i-1,j)+1;
return go(i+1,j)+1;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>m;
for(ll i=0; i<n; i++)
for(ll j=0; j<m; j++)
{
cin>>c[i][j];
if(c[i][j]=='o')
x=i,y=j;
}
ans.F=1e9;
ans=min({go(x-1,y),'N'},ans);
ans=min({go(x+1,y),'S'},ans);
ans=min({go(x,y+1),'E'},ans);
ans=min({go(x,y-1),'W'},ans);
if(ans.F>=1e9)
cout<<":(";
else
cout<<":)\n"<<ans.S;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |