Submission #373525

#TimeUsernameProblemLanguageResultExecution timeMemory
373525FystyPatkice (COCI20_patkice)C++17
30 / 50
1 ms888 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; typedef pair<int,int> pii; const ll INF=1e18; #define MottoHayaku ios::sync_with_stdio(0);cin.tie(0); #define rep(i,n) for(int i=0;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define F first #define S second #define pb push_back ll dist[105][105]; char dir='X'; vector<pll> ed[105][105]; void dijk(ll sx,ll sy,ll ex,ll ey) { queue<pll> q; q.push({sx,sy}); dist[sx][sy]=0; while(!q.empty()) { pll p=q.front();q.pop(); for(auto u:ed[p.F][p.S]) { if(dist[u.F][u.S]<=dist[p.F][p.S]+1) continue; dist[u.F][u.S]=dist[p.F][p.S]+1; if(u.F==ex&&u.S==ey) { if(u.F==p.F-1) dir=min(dir,'S'); else if(u.F==p.F+1) dir=min(dir,'N'); else if(u.S==p.S-1) dir=min(dir,'E'); else dir=min(dir,'W'); } q.push(u); } } } string s[105]; int main() { MottoHayaku ll n,m,sx,sy,ex,ey; cin>>n>>m; rep(i,n) cin>>s[i]; rep(i,n) { rep(j,m) { dist[i][j]=INF; if(s[i][j]=='^') ed[i-1][j].pb({i,j}); if(s[i][j]=='v') ed[i+1][j].pb({i,j}); if(s[i][j]=='<') ed[i][j-1].pb({i,j}); if(s[i][j]=='>') ed[i][j+1].pb({i,j}); if(s[i][j]=='x') sx=i,sy=j; if(s[i][j]=='o') { ex=i,ey=j; ed[i-1][j].pb({i,j}); ed[i+1][j].pb({i,j}); ed[i][j-1].pb({i,j}); ed[i][j+1].pb({i,j}); } } } dijk(sx,sy,ex,ey); if(dist[ex][ey]==INF) cout<<":(\n"; else cout<<":)\n"<<dir<<"\n"; }

Compilation message (stderr)

patkice.cpp: In function 'int main()':
patkice.cpp:67:19: warning: 'ey' may be used uninitialized in this function [-Wmaybe-uninitialized]
   67 |     if(dist[ex][ey]==INF) cout<<":(\n";
      |        ~~~~~~~~~~~^
patkice.cpp:67:19: warning: 'ex' may be used uninitialized in this function [-Wmaybe-uninitialized]
patkice.cpp:66:9: warning: 'sy' may be used uninitialized in this function [-Wmaybe-uninitialized]
   66 |     dijk(sx,sy,ex,ey);
      |     ~~~~^~~~~~~~~~~~~
patkice.cpp:66:9: warning: 'sx' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...