Submission #68368

#TimeUsernameProblemLanguageResultExecution timeMemory
68368thebesJakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
1096 ms97372 KiB
#include <bits/stdc++.h> using namespace std; const int MN = 30004, MS = 180; int N, M, S, i, j, src, des, x, y, ent[MN]; struct pir{int f, s, p;}; vector<pir> e[MN]; bitset<MS> pw[MN]; pir pr(int f, int s, int p){pir z={f,s,p}; return z;} struct pq{bool operator()(const pir&i,const pir&j){return(i.s>j.s);}}; priority_queue<pir,vector<pir>,pq> q; int main(){ for(scanf("%d%d",&N,&M),S=sqrt(N+0.0);i<M;i++){ scanf("%d%d",&x,&y); if(i == 0) src = x; else if(i == 1) des = x; if(y >= S){ for(j=1;x-j*y>=0;j++) e[x].push_back(pr(x-j*y,j,-1)); for(j=1;x+j*y<N;j++) e[x].push_back(pr(x+j*y,j,-1)); } else e[x].push_back(pr(x,0,y)); } pir st = {src, 0, -1}; q.push(st); while(!q.empty()){ pir _ = q.top(); q.pop(); if(_.f == des){printf("%d\n",_.s); return 0;} if(_.p == -1){ if(ent[_.f]) continue; else ent[_.f] = 1; for(auto v : e[_.f]){ if(v.p == -1 && !ent[v.f]) q.push(pr(v.f,v.s+_.s,v.p)); else if(v.p != -1 && !pw[v.f][v.p]) q.push(pr(v.f,v.s+_.s,v.p)); } } else{ if(pw[_.f][_.p]) continue; else pw[_.f][_.p] = 1; if(!ent[_.f]) q.push(pr(_.f,_.s,-1)); if(_.f+_.p < N && !pw[_.f+_.p][_.p]) q.push(pr(_.f+_.p,_.s+1,_.p)); if(_.f-_.p >=0 && !pw[_.f-_.p][_.p]) q.push(pr(_.f-_.p,_.s+1,_.p)); } } printf("-1\n"); return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:12:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(scanf("%d%d",&N,&M),S=sqrt(N+0.0);i<M;i++){
      ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&x,&y);
   ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...