Submission #950405

#TimeUsernameProblemLanguageResultExecution timeMemory
950405UnforgettableplJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1048 ms19564 KiB
#include <bits/stdc++.h> using namespace std; #define int long long priority_queue<pair<int,int>> q; vector<int> buildings[30001]; int power[30001]; set<int> visited; int n; inline void adddoge(int x,int building,int dist){ for(int i:visited)if(abs(building-i)%power[x]==0){ q.emplace(dist-(abs(building-i)/power[x]),i); } } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int m; cin >> n >> m; int base,tar; cin>>base>>power[0]>>tar>>power[1]; buildings[base].emplace_back(0); buildings[tar].emplace_back(1); for(int i=2;i<m;i++){ int b;cin>>b>>power[i]; buildings[b].emplace_back(i); } for(int i=0;i<n;i++)visited.insert(i); q.emplace(0,base); while(!q.empty()){ auto curr = q.top();q.pop(); if(visited.count(curr.second)==0)continue; visited.erase(curr.second); if(curr.second==tar){ cout << -curr.first << '\n'; return 0; } for(int&i:buildings[curr.second])adddoge(i,curr.second,curr.first); } cout << "-1\n"; }
#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...