Submission #953647

#TimeUsernameProblemLanguageResultExecution timeMemory
953647UnforgettableplJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
264 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define int long long priority_queue<pair<int,int>> q; vector<pair<int,int>> adj[6000000]; bool visited[6000000]; int n; const int threshold = 173; void adddoge(int power,int building){ if(power>threshold){ int minimum = building - power*(building/power); for (int i = minimum; i < n; i += power) adj[building*174].emplace_back(i*174,abs(building-i)/power); } else { adj[building*174].emplace_back(building*174+power,0); } } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int m; cin >> n >> m; int base,tar,bp,tp; cin>>base>>bp>>tar>>tp; adddoge(bp,base); adddoge(tp,tar); for(int i=2;i<m;i++){ int b,p;cin>>b>>p; adddoge(p,b); } for(int i=0;i<n;i++){ int b = i*174; for(int j=b+1;j<b+174;j++){ adj[j].emplace_back(b,0); } } for(int power=1;power<=173;power++){ int offset = 174*power; for(int i=power;i<n;i++){ adj[i*174+power].emplace_back(i*174+power-offset,1); } for(int i=n-power-1;i>=0;i--){ adj[i*174+power].emplace_back(i*174+power+offset,1); } } base*=174;tar*=174; q.emplace(0, base); while(!q.empty()){ auto curr = q.top();q.pop(); if(visited[curr.second])continue; visited[curr.second]=true; if(curr.second==tar){ cout << -curr.first << '\n'; return 0; } for(auto&i:adj[curr.second])if(!visited[i.first])q.emplace(curr.first-i.second,i.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...