Submission #602479

#TimeUsernameProblemLanguageResultExecution timeMemory
602479AGEPatkice (COCI20_patkice)C++14
30 / 50
5 ms6636 KiB
#include<bits/stdc++.h> #define F first #define S second #define int long long #define pb push_back using namespace std; const int N=2e5+10,M=3e3+10,mod=1e9+7; int idx[4]={0,0,-1,1}; int idy[4]={1,-1,0,0}; char x[4]={'E','W','N','S'}; int ans[150][150],n,m; string s[N]; bool inside(int x,int y){ return ((x>=0)&&(x<n)&&(y<m)&&(y>=0)&&(ans[x][y]==-1e18)); } void floodfill(int x,int y,int type){ if(s[x][y]=='x') return ; else if(s[x][y]=='>'){ if(!inside(x,y+1)) return ; ans[x][y+1]=ans[x][y]+1; floodfill(x,y+1,type); } else if(s[x][y]=='<'){ if(!inside(x,y-1)) return ; ans[x][y-1]=ans[x][y]+1; floodfill(x,y-1,type); } else if(s[x][y]=='v'){ if(!inside(x+1,y)) return ; ans[x+1][y]=ans[x][y]+1; floodfill(x+1,y,type); } else if(s[x][y]=='^'){ if(!inside(x-1,y)) return ; ans[x-1][y]=ans[x][y]+1; floodfill(x-1,y,type); } else{ int newx=x+idx[type]; int newy=y+idy[type]; if(!inside(newx,newy)) return ; ans[newx][newy]=ans[x][y]+1; floodfill(newx,newy,type); } } main() { cin>>n>>m; for(int i=0;i<n;i++) cin>>s[i]; int indexx,indexy; for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(s[i][j]=='o') indexx=i,indexy=j; int indexx2,indexy2; for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(s[i][j]=='x') indexx2=i,indexy2=j; vector<pair<int,char>>v; for(int i=0;i<4;i++){ for(int j=0;j<n;j++) for(int k=0;k<m;k++) ans[j][k]=-1e18; ans[indexx][indexy]=0; floodfill(indexx,indexy,i); if(ans[indexx2][indexy2]!=-1e18) v.pb({ans[indexx2][indexy2],x[i]}); } if(v.size()==0){ cout<<":("<<endl; return 0; } sort(v.begin(),v.end()); cout<<":)"<<endl; cout<<v[0].S<<endl; return 0; }

Compilation message (stderr)

patkice.cpp:77:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   77 | main()
      | ^~~~
patkice.cpp: In function 'int main()':
patkice.cpp:107:18: warning: 'indexy' may be used uninitialized in this function [-Wmaybe-uninitialized]
  107 |         floodfill(indexx,indexy,i);
      |         ~~~~~~~~~^~~~~~~~~~~~~~~~~
patkice.cpp:107:18: warning: 'indexx' may be used uninitialized in this function [-Wmaybe-uninitialized]
patkice.cpp:109:32: warning: 'indexy2' may be used uninitialized in this function [-Wmaybe-uninitialized]
  109 |         if(ans[indexx2][indexy2]!=-1e18)
      |            ~~~~~~~~~~~~~~~~~~~~^
patkice.cpp:109:32: warning: 'indexx2' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...