Submission #402252

#TimeUsernameProblemLanguageResultExecution timeMemory
402252keta_tsimakuridzePatkice (COCI20_patkice)C++14
50 / 50
1 ms392 KiB
#include<bits/stdc++.h> #define f first #define int long long #define s second using namespace std; const int N=105,mod=1e9+7,Inf = 1e15 + 1; int t,dist[N][N],n,m; char a[N][N]; queue<pair<int,pair<int,int> > > q; string s; bool ok(int x,int y){ if(min(x,y)<1 || x>n || y>m) return 0; return 1; } void bfs(){ for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) dist[i][j] = Inf; while(q.size()){ int d = q.front().f; int i=q.front().s.f; int j=q.front().s.s; q.pop(); dist[i][j] = d; if(a[i][j] == '.' || a[i][j]=='x') continue; int dx=0,dy=0; if(a[i][j]=='>') dx=0,dy=1; else if(a[i][j]=='<') dx=0,dy=-1; else if(a[i][j]=='^') dx=-1,dy=0; else dx=1,dy=0; if(dist[i+dx][j+dy] > d+1){ dist[i+dx][j+dy] = d+1; q.push({d+1,{i+dx,j+dy}}); } } } main(){ // t=1; cin >> n >> m; int I=0,J=0,I_,J_; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>a[i][j]; if(a[i][j] == 'o') I=i,J=j; else if(a[i][j] =='x') I_=i,J_=j; } } // E N S W int ans = Inf,i=I,j=J; char ch='a'; if(ok(i,j+1)) q.push({0,{i,j+1}}); bfs(); ans = dist[I_][J_]; ch='E'; if(ok(i-1,j)) q.push({0,{i-1,j}}); bfs(); if(dist[I_][J_]<ans) ans = dist[I_][J_],ch='N'; if(ok(i+1,j)) q.push({0,{i+1,j}}); bfs(); if(dist[I_][J_]<ans) ans = dist[I_][J_],ch='S'; if(ok(i+1,j-1)) q.push({0,{i,j-1}}); bfs(); if(dist[I_][J_]<ans) ans = dist[I_][J_],ch='W'; if(ans==Inf)cout<<":("<<endl; else cout<<":)"<<endl,cout<<ch; }

Compilation message (stderr)

patkice.cpp:37:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   37 |  main(){
      |  ^~~~
patkice.cpp: In function 'int main()':
patkice.cpp:53:6: warning: 'J_' may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |  ans = dist[I_][J_]; ch='E';
      |  ~~~~^~~~~~~~~~~~~~
patkice.cpp:53:6: warning: 'I_' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...