Submission #383358

#TimeUsernameProblemLanguageResultExecution timeMemory
383358tjrwodnjs999Jakarta Skyscrapers (APIO15_skyscraper)C++11
10 / 100
3 ms2028 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]; ll dist[30005]; vector<int> Map[30005],adj[30005],vt[10][10]; priority_queue<pair<ll,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<10;j++) vt[j][B[i]%j].push_back(i); } for(int i=1;i<=m;i++){ if(P[i]>=10){ for(int j:Map[B[i]]) if(j!=i) adj[i].push_back(j); for(int j=B[i]+P[i];j<n;j++){ for(int k:Map[j]) adj[i].push_back(k); } for(int j=B[i]-P[i];j>=0;j--){ for(int k:Map[j]) adj[i].push_back(k); } } } fill(dist,dist+30005,1e9); dist[1]=0; pq.push({0,1}); while(!pq.empty()){ int now=pq.top().second; ll cost=-pq.top().first; pq.pop(); if(dist[now]<cost) continue; if(P[now]>=10){ for(int i:adj[now]){ 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("%lld",dist[2]==1e9?-1: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...