# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
820174 | lprochniak | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 55 ms | 34776 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 MAX 30009
#define pb push_back
#define st first
#define nd second
int n,m;
vector<int> p[MAX];
struct Node{
int v;
int waga;
};
vector<Node> edges[MAX];
int wyn[MAX];
void dijkstra(int s){
priority_queue<pair<int,int>> q;
q.push({0,s});
while(!q.empty()){
pair<int,int> t = q.top();
q.pop();
t.st = -t.st;
for(auto x:edges[t.nd]){
if(t.st+x.waga<wyn[x.v]){
wyn[x.v] = t.st + x.waga;
q.push({-wyn[x.v],x.v});
}
}
}
}
int main(){
cin>>n>>m;
memset(p,0,sizeof p);
int whereZero,whereOne;
for(int i=0;i<m;i++){
int b,pwr;
cin>>b>>pwr;
p[b].pb(pwr);
if(i == 0)
whereZero = b;
else if(i == 1)
whereOne = b;
}
for(int i=0;i<n;i++){
if(p[i].empty()) continue;
for(auto pwr:p[i]){
int idx = i-pwr;
int ile = 1;
while(idx>=0){
edges[i].pb({idx,ile});
idx-=pwr,ile++;
}
idx = i+pwr;
ile = 1;
while(idx<n){
edges[i].pb({idx,ile});
idx+=pwr,ile++;
}
}
}
for(int i=1;i<n;i++){
wyn[i] = 1000000000;
}
dijkstra(whereZero);
if(wyn[whereOne] == 1000000000){
cout<<"-1\n";
} else
cout<<wyn[whereOne]<<"\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... |