Submission #447675

#TimeUsernameProblemLanguageResultExecution timeMemory
447675ApiramPatkice (COCI20_patkice)C++14
50 / 50
1 ms332 KiB
#include<bits/stdc++.h> using namespace std; int ans =INT_MAX; struct points { int x,y,cnts; char c; }; vector<string>arr(200); points add(points startt,int i,int j,int k,char b){ points a; a.x=startt.x+i; a.y=startt.y+j; a.cnts=startt.cnts+k; a.c =b; return a; } bool check(points u,int n,int m){ if (u.x<0||u.y<0)return false; if (u.x>=n||u.y>=m)return false; if (arr[u.x][u.y]=='.')return false; if (u.cnts>ans)return false; return true; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n,m;cin>>n>>m; points startt,endd; for (int i = 0; i<n;++i){ cin>>arr[i]; for (int j = 0;j<m;++j){ if (arr[i][j]=='x'){ endd.x=i; endd.y=j; endd.cnts=0; } else if(arr[i][j]=='o'){ startt.x=i; startt.y=j; startt.cnts=0; } } } queue<points>q; q.push(add(startt,0,1,1,'E')); q.push(add(startt,1,0,1,'S')); q.push(add(startt,0,-1,1,'W')); q.push(add(startt,-1,0,1,'N')); vector<vector<int>>dist(n,vector<int>(m,INT_MAX)); dist[startt.x][startt.y]=0; vector<pair<int,char>>answer; while(!q.empty()){ points u = q.front(); q.pop(); if (!check(u,n,m))continue; if (arr[u.x][u.y]=='x'){ ans=min(ans,u.cnts); answer.push_back({u.cnts,u.c}); continue; } if (dist[u.x][u.y]<u.cnts)continue; dist[u.x][u.y]=u.cnts; if (arr[u.x][u.y]=='>'){ q.push(add(u,0,1,1,u.c)); } else if (arr[u.x][u.y]=='<'){ q.push(add(u,0,-1,1,u.c)); } else if (arr[u.x][u.y]=='^'){ q.push(add(u,-1,0,1,u.c)); } else{ q.push(add(u,1,0,1,u.c)); } } sort(answer.begin(),answer.end()); if (ans!=INT_MAX){ cout<<":)\n"; cout<<answer[0].second<<endl; } else{ cout<<":(\n"; } return 0;}

Compilation message (stderr)

patkice.cpp: In function 'int main()':
patkice.cpp:28:15: warning: variable 'endd' set but not used [-Wunused-but-set-variable]
   28 | points startt,endd;
      |               ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...