Submission #487840

#TimeUsernameProblemLanguageResultExecution timeMemory
487840inksamuraiPatkice (COCI20_patkice)C++17
0 / 50
1 ms332 KiB
#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; 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) and usd[nex][ney]==0){ self(self,nex,ney); } }; vec(string) pans; 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); if(pok){ if(dir==0){ pans.pb("N"); } if(dir==1){ pans.pb("S"); } if(dir==2){ pans.pb("E"); } if(dir==3){ pans.pb("W"); } } } } if(sz(pans)==0){ cout<<":(\n"; }else{ sort(all(pans)); cout<<":)\n"; cout<<pans[0]<<"\n"; } // return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...