# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
545746 | AJ00 | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 216 ms | 130616 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>
using namespace std;
#define int long long
const int INF = 1e18;
vector<vector<pair<int,int>>> adj(30000);
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int t=1,n,k,st,fin,B,P;
cin >> n >> k;
// pair<int,int> doge[k];
vector<set<int>> doges(n);
vector<int> dist(n);
// memset(dist, 0x3f, sizeof dist);
for (int i = 0; i < k; i++){
cin >> B >> P;
doges[B].insert(P);
if (i == 0){
st = B;
}
if (i == 1){
fin = B;
}
}
//sort(doge,doge+k);
for (int i = 0; i < n; i++){
for (int jump: doges[i]){
for (int j = i+jump; j < n; j += jump){
adj[i].push_back({j,((j-i)/jump)});
if (doges[j].find(jump) != doges[j].end()){
break;
}
}
for (int j = i-jump; j >= 0; j -= jump){
adj[i].push_back({j,((i-j)/jump)});
if (doges[j].find(jump) != doges[j].end()){
break;
}
}
}
}
for (int i = 0; i < n; i++){
dist[i] = INF;
}
priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
pq.push({0,st});
dist[st] = 0;
while(!pq.empty()){
int distp = pq.top().first;
int p = pq.top().second;
pq.pop();
if (distp != dist[p]){
continue;
}
for (auto ch: adj[p]){
if (dist[p] + ch.second < dist[ch.first]){
dist[ch.first] = dist[p] + ch.second;
pq.push({dist[ch.first],ch.first});
}
}
}
dist[fin] >= INF ? cout << "-1\n" : cout << dist[fin] << "\n";
return 0;
}
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... |