Submission #26867

#TimeUsernameProblemLanguageResultExecution timeMemory
26867szawinisJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
0 ms3716 KiB
#include <bits/stdc++.h> using namespace std; const int MAX = (3e4)+1, INF = 1e9; int n, m, bc, sz, d[MAX]; vector<int> a[MAX]; vector<pair<int,int> > g[MAX]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; bc = sqrt(n), sz = n/bc; for(int i = 0, pos, len; i < m; i++) { cin >> pos >> len; a[pos].push_back(len); } for(int i = 0; i < n; i++) for(int len: a[i]) { for(int j = i-len; j >= 0; j -= len) g[i].emplace_back(j, (i-j)/len); for(int j = i+len; j < n; j += len) g[i].emplace_back(j, (j-i)/len); } fill(d+1, d+n, INF); priority_queue<pair<int,int> > pq; pq.emplace(0, 0); while(!pq.empty()) { int u = pq.top().second; pq.pop(); for(auto p: g[u]) { int v, w; tie(v, w) = p; if(d[u] + w < d[v]) { d[v] = d[u] + w; pq.emplace(-d[v], v); } } } cout << (d[1] == INF ? -1 : d[1]); }
#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...