# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
383354 | tjrwodnjs999 | Jakarta Skyscrapers (APIO15_skyscraper) | C++11 | 30 ms | 3564 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>
#define ll long long
#define x first
#define y second
using namespace std;
int n,m,B[30005],P[30005];
int dist[30005];
vector<int> Map[30005],adj[30005],vt[100][100];
priority_queue<pair<int,int>> pq;
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
scanf("%d%d",&B[i],&P[i]);
Map[B[i]].push_back(i);
for(int j=1;j<100;j++) vt[j][B[i]%j].push_back(i);
}
fill(dist,dist+30005,1e9);
dist[1]=0; pq.push({0,1});
while(!pq.empty()){
int now=pq.top().second;
int cost=-pq.top().first; pq.pop();
if(dist[now]<cost) continue;
if(P[now]>=100){
for(int i:Map[B[now]]) if(i!=now){
ll d=abs(B[i]-B[now])/P[now];
if(dist[i]>cost+d) dist[i]=cost+d,pq.push({-dist[i],i});
}
for(int j=B[now]+P[now];j<n;j++) for(int i:Map[j]){
ll d=abs(B[i]-B[now])/P[now];
if(dist[i]>cost+d) dist[i]=cost+d,pq.push({-dist[i],i});
}
for(int j=B[now]-P[now];j>=0;j--) for(int i:Map[j]){
ll d=abs(B[i]-B[now])/P[now];
if(dist[i]>cost+d) dist[i]=cost+d,pq.push({-dist[i],i});
}
}
else{
for(int i:vt[P[now]][B[now]%P[now]]){
ll d=abs(B[i]-B[now])/P[now];
if(dist[i]>cost+d) dist[i]=cost+d,pq.push({-dist[i],i});
}
}
}
printf("%d",dist[2]==1e9?-1:dist[2]);
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... |