제출 #146036

#제출 시각아이디문제언어결과실행 시간메모리
146036str0ctJakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
1066 ms2696 KiB
#include<bits/stdc++.h> using namespace std; using pii=pair <int,int>; int vis[30303]; int N,M; pair <int,int> ipt[30303]; vector <int> V[30303]; priority_queue<pii,vector<pii>,greater<pii> > pq; void dijkstra(){ pq.push({0,ipt[0].first}); vis[ipt[0].first]=0; while(!pq.empty()){ int a=pq.top().first,b=pq.top().second; pq.pop(); if(a<=vis[b]){ for(auto i:V[b]){ int fl1=0,fl2=0; for(int k=1;;k++){ if(fl1&&fl2)break; if(k*i+b<N&&!fl1){if(vis[b+i*k]>a+k){ pq.push({a+k,b+i*k}); vis[b+i*k]=a+k; if(binary_search(V[b+i*k].begin(),V[b+i*k].end(),i))fl1=1; }} else fl1=1; if(b-k*i>=0&&!fl2){if(vis[b-i*k]>a+k){ pq.push({a+k,b-i*k}); vis[b-i*k]=a+k; auto it=lower_bound(V[b-i*k].begin(),V[b-i*k].end(),i); if(it!=V[b-i*k].end()&&*it==i)fl2=1; }} else fl2=1; } } } } } int main(){ fill(vis,vis+30303,101010); scanf("%d%d",&N,&M); for(int i=0;i<M;i++){ scanf("%d%d",&ipt[i].first,&ipt[i].second); V[ipt[i].first].push_back(ipt[i].second); } for(int i=0;i<30003;i++){ sort(V[i].begin(),V[i].end()); V[i].erase(unique(V[i].begin(),V[i].end()),V[i].end()); } dijkstra(); if(vis[ipt[1].first]!=101010)printf("%d",vis[ipt[1].first]); else puts("-1"); }

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

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&N,&M);
     ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&ipt[i].first,&ipt[i].second);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...