# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
566592 | ac2hu | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 789 ms | 6612 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#ifdef DEBUG
#include "../templates/debug.h"
#else
#define deb(x...)
#endif
using namespace std;
#define int long long
signed main() {
iostream::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int n, m;cin >> n >> m;
n++;
vector<pair<int,int>> doge(m);
for(auto &[x,y] : doge)cin >> x >> y;
vector<vector<int>> val(n);
for(auto [x, y] : doge){
val[x].push_back(y);
}
vector<int> dist(n, 1e18);
dist[doge[0].first] = 0;
priority_queue<pair<int,int>> pq;
pq.push({-dist[doge[0].first], doge[0].first});
while(!pq.empty()){
auto [dd, x] = pq.top();
pq.pop();
dd = -dd;
if(dist[x] < dd)continue;
for(int e : val[x]){
int c = 0;
for(int j = x;j<n;j+=e){
if(dist[j] > dist[x] + c){
dist[j] = dist[x] + c;
pq.push({-dist[j], j});
}
c++;
}
c = 0;
for(int j = x;j>=0;j-=e){
if(dist[j] > dist[x] + c){
dist[j] = dist[x] + c;
pq.push({-dist[j], j});
}
c++;
}
}
}
int r = doge[1].first;
if(dist[r] > 1e17)
cout << -1 << "\n";
else
cout << dist[r] << "\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |