Submission #977645

#TimeUsernameProblemLanguageResultExecution timeMemory
977645nninJakarta Skyscrapers (APIO15_skyscraper)C++17
36 / 100
264 ms262144 KiB
#include<bits/stdc++.h> using namespace std; #define pii pair<int,int> using ll = long long; #define pli pair<ll, int> int N, M, B[30005], P[30005]; vector<pii> adj[30005]; ll mindis[30005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>N>>M; for(int i=0;i<M;i++) { cin>>B[i]>>P[i]; for(int j=1;B[i]-(j*P[i])>=0;j++) { adj[B[i]].push_back({B[i]-(j*P[i]), j}); } for(int j=1;B[i]+(j*P[i])<N;j++) { adj[B[i]].push_back({B[i]+(j*P[i]), j}); } } for(int i=0;i<N;i++) mindis[i] = 1e18; priority_queue<pli, vector<pli>, greater<pli>> pq; pq.push({0ll, B[0]}); mindis[B[0]] = 0ll; while(!pq.empty()) { auto [dis, u] = pq.top(); pq.pop(); if(u==B[1]) break; if(mindis[u]!=dis) continue; for(auto [v, w]:adj[u]) { if(mindis[v]>dis+w) { mindis[v] = dis+w; pq.push({mindis[v], v}); } } } if(mindis[B[1]]==1e18) cout<<-1; else cout<<mindis[B[1]]; } /* 5 3 0 2 1 1 4 1 */
#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...