Submission #976158

#TimeUsernameProblemLanguageResultExecution timeMemory
976158SuPythonyJakarta Skyscrapers (APIO15_skyscraper)C++17
0 / 100
1 ms596 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n,m; cin>>n>>m; vector<pair<int,int>> doges; for (int i=0; i<n; i++) { int b,p; cin>>b>>p; doges.push_back({b,p}); } vector<vector<pair<int,int>>> al(n,vector<pair<int,int>>()); for (int i=0; i<n; i++) { if (i==1) continue; for (int j=0; j<n; j++) { if (i==j) continue; int d=abs(doges[i].first-doges[j].first); if (d%doges[i].second==0) { al[i].push_back({j,d/doges[i].second}); } } } vector<int> dist(n,1e9); dist[0]=0; priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> p; p.push({0,0}); while (!p.empty()) { int t=p.top().second; p.pop(); for (auto v: al[t]) { if (dist[t]+v.second<dist[v.first]) { dist[v.first]=dist[t]+v.second; p.push({dist[v.first],v.first}); } } } cout<<dist[1]; return 0; }
#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...