Submission #383351

#TimeUsernameProblemLanguageResultExecution timeMemory
383351tjrwodnjs999Jakarta Skyscrapers (APIO15_skyscraper)C++11
0 / 100
136 ms213612 KiB
#include <bits/stdc++.h> #define ll long long #define x first #define y second using namespace std; int n,m,B[30005],P[30005]; int dist[30005]; vector<int> Map[30005],adj[30005],vt[3000][3000]; priority_queue<pair<int,int>> pq; int main() { scanf("%d%d",&n,&m); for(int i=1;i<=m;i++){ scanf("%d%d",&B[i],&P[i]); Map[B[i]].push_back(i); for(int j=1;j<3000;j++) vt[j][B[i]%j].push_back(i); } fill(dist,dist+30005,1e9); dist[1]=0; pq.push({0,1}); while(!pq.empty()){ int now=pq.top().second; int cost=-pq.top().first; pq.pop(); if(dist[now]<cost) continue; if(P[now]>=3000){ for(int i:Map[B[now]]) if(i!=now){ ll d=abs(B[i]-B[now])/P[now]; if(dist[i]>cost+d) dist[i]=cost+d,pq.push({-dist[i],i}); } for(int j=B[now]+P[now];j<n;j++) for(int i:Map[j]){ ll d=abs(B[i]-B[now])/P[now]; if(dist[i]>cost+d) dist[i]=cost+d,pq.push({-dist[i],i}); } for(int j=B[now]-P[now];j>=0;j--) for(int i:Map[j]){ ll d=abs(B[i]-B[now])/P[now]; if(dist[i]>cost+d) dist[i]=cost+d,pq.push({-dist[i],i}); } } else{ for(int i:vt[P[now]][B[now]%P[now]]){ ll d=abs(B[i]-B[now])/P[now]; if(dist[i]>cost+d) dist[i]=cost+d,pq.push({-dist[i],i}); } } } printf("%d",dist[2]); return 0; }

Compilation message (stderr)

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