#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _3HaBFkZ ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
using pii=pair<int,int>;
using vi=vector<int>;
int main(){
_3HaBFkZ;
int h,w;
cin>>h>>w;
vec(vec(char)) a(h,vec(char)(w));
rep(i,h)rep(j,w) cin>>a[i][j];
pii hm={-1,-1};
rep(i,h)rep(j,w){
if(a[i][j]=='o'){
hm={i,j};
break;
}
}
const int di[]={1,-1,0,0};
const int dj[]={0,0,1,-1};
auto ok=[&](int x,int y)->bool{
return !(min(x,y)<0 or x>=h or y>=w);
};
vec(vi) usd(h,vi(w));
bool pok=0;
auto dfs=[&](auto self,int x,int y){
if(usd[x][y]) return;
usd[x][y]=1;
// cout<<x<<" "<<y<<"\n";
if(a[x][y]=='.' or a[x][y]=='o') return;
if(a[x][y]=='x'){
pok=1;
return;
}
char ch=a[x][y];
int dir=(ch=='v'?0:ch=='>'?2:ch=='<'?3:1);
int nex=x+di[dir],ney=y+dj[dir];
if(ok(nex,ney)){
self(self,nex,ney);
}
};
rep(dir,4){
int nex=hm.fi+di[dir],ney=hm.se+dj[dir];
if(ok(nex,ney)){
usd=vec(vi)(h,vi(w,0));
dfs(dfs,nex,ney);
// cout<<nex<<" "<<ney<<"\n";
if(pok){
cout<<":)\n";
if(dir==0) cout<<"N\n";
if(dir==1) cout<<"S\n";
if(dir==2) cout<<"E\n";
if(dir==3) cout<<"W\n";
exit(0);
}
}
}
cout<<":(\n";
//
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Incorrect |
0 ms |
336 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |