제출 #27345

#제출 시각아이디문제언어결과실행 시간메모리
27345TAMREFJakarta Skyscrapers (APIO15_skyscraper)C++11
57 / 100
1000 ms9440 KiB
#include <bits/stdc++.h> #define va first #define vb second #define mp make_pair #define all(x) x.begin(),x.end() using namespace std; typedef pair<int,int> pii; const int mx=30005; int dist[mx]; pii doge[mx]; vector<int> C[mx]; int N,M; void input(){ scanf("%d%d",&N,&M); for(int i=0;i<M;i++){ scanf("%d%d",&doge[i].va,&doge[i].vb); C[doge[i].va].push_back(doge[i].vb); } for(int i=0;i<N;i++) sort(all(C[i]),greater<int>()); fill(dist,dist+N,(int)1e9); } void dijk(int s){ priority_queue<pii,vector<pii>,greater<pii>> q; q.push(mp(dist[s]=0,s)); pii t; while(!q.empty()){ t=q.top(); q.pop(); if(t.va>dist[t.vb]) continue; for(int p : C[t.vb]){ for(int x=t.vb+p;x<N;x+=p){ if(!C[x].size()) continue; if(binary_search(all(C[x]),p)){ if(dist[x]>=t.va+(x-t.vb)/p){ q.push(mp(dist[x]=t.va+(x-t.vb)/p,x)); break; } } if(dist[x]>=t.va+(x-t.vb)/p) q.push(mp(dist[x]=t.va+(x-t.vb)/p,x)); } for(int x=t.vb-p;x>=0;x-=p){ if(!C[x].size()) continue; if(binary_search(all(C[x]),p)){ if(dist[x]>=t.va+(t.vb-x)/p){ q.push(mp(dist[x]=t.va+(t.vb-x)/p,x)); break; } } if(dist[x]>=t.va+(t.vb-x)/p) q.push(mp(dist[x]=t.va+(t.vb-x)/p,x)); } } } } int main(){ input(); dijk(doge[0].va); printf("%d\n",dist[doge[1].va]==(int)1e9?-1:dist[doge[1].va]); }

컴파일 시 표준 에러 (stderr) 메시지

skyscraper.cpp: In function 'void input()':
skyscraper.cpp:14:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&N,&M);
                        ^
skyscraper.cpp:16:46: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&doge[i].va,&doge[i].vb);
                                              ^
#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...