Submission #1085785

#TimeUsernameProblemLanguageResultExecution timeMemory
1085785codexistentJakarta Skyscrapers (APIO15_skyscraper)C++14
36 / 100
1097 ms2268 KiB
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = a; i <= b; i++) #define MAXN 30005 int n, m, t[MAXN], s, e; pair<int, int> d[MAXN]; vector<int> p[MAXN]; priority_queue<pair<int, int>> pq; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; FOR(i, 0, m - 1) t[i] = -1; FOR(i, 0, m - 1){ cin >> d[i].first >> d[i].second; if(i == 0) { s = d[i].first; t[0] = 0; pq.push({-t[0], 0}); } if(i == 1) e = d[i].first; } while(pq.size()){ int v = pq.top().first; int pqi = pq.top().second; pq.pop(); if(t[pqi] != -v) continue; // cout << pqi << " " << -v << endl; FOR(i, 0, m - 1) if(i != pqi){ if(abs(d[pqi].first - d[i].first) % d[pqi].second == 0 && (t[i] == -1 || t[pqi] + abs(d[pqi].first - d[i].first) / d[pqi].second < t[i])){ t[i] = t[pqi] + abs(d[pqi].first - d[i].first) / d[pqi].second; pq.push({-t[i], i}); // cout << " => " << i << " " << t[i] << " " << d[pqi].second << endl; } } } cout << t[1] << endl; }
#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...