Submission #953634

#TimeUsernameProblemLanguageResultExecution timeMemory
953634UnforgettableplJakarta Skyscrapers (APIO15_skyscraper)C++17
22 / 100
68 ms137148 KiB
#include <bits/stdc++.h> using namespace std; #define int long long priority_queue<pair<int,pair<int,int>>> q; vector<pair<pair<int,int>,int>> adj[30000][174]; bool visited[30000][174]; 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][0].emplace_back(make_pair(i,0),1); } else { adj[building][0].emplace_back(make_pair(building,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++){ for(int j=1;j<174;j++){ adj[i][j].emplace_back(make_pair(i,0),0); } } for(int power=1;power<=173;power++){ for(int i=power;i<n;i++){ adj[i][power].emplace_back(make_pair(i-power,power),1); } for(int i=n-power-1;i>=0;i--){ adj[i][power].emplace_back(make_pair(i+power,power),1); } } q.emplace(0, make_pair(base,0)); while(!q.empty()){ auto curr = q.top();q.pop(); if(visited[curr.second.first][curr.second.second])continue; visited[curr.second.first][curr.second.second]=true; if(curr.second.first==tar){ cout << -curr.first << '\n'; return 0; } for(auto&i:adj[curr.second.first][curr.second.second])if(!visited[i.first.first][i.first.second])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...