Submission #321570

#TimeUsernameProblemLanguageResultExecution timeMemory
321570minoumJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
498 ms262148 KiB
#include<bits/stdc++.h> using namespace std; typedef long long int ll; const int MAXN = 3e4 + 5, inf = INT_MAX / 2; int n, m, b[MAXN], p[MAXN], d[MAXN], cnt[MAXN], sz = 0; vector <pair<int, int>> adj[MAXN]; set <pair<int,int>> all; void dij(){ set <pair<int,int>> s; for(int i = 0; i < n; i++) d[i] = inf; d[b[0]] = 0; s.insert({0,b[0]}); while(!s.empty()){ int v = s.begin()->second; s.erase(*s.begin()); for(auto i: adj[v]){ int u = i.first, w = i.second; if(d[u] > d[v] + w){ s.erase({d[u], u}); d[u] = d[v] + w; s.insert({d[u], u}); } } } return; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 0; i < m; i++){ cin >> b[i] >> p[i]; cnt[b[i]]++; all.insert({b[i], p[i]}); } sz = (int)all.size(); for(int i = 0; i < sz; i++){ int bi = all.begin()->first, pi = all.begin()->second; all.erase(*all.begin()); for(int j = bi % pi; j < n; j += pi) if(j != bi && cnt[j]) adj[bi].push_back({j, abs(bi - j) / pi}); } dij(); cout << ((d[b[1]] >= inf)?-1:d[b[1]]) << endl; 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...