# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
383358 | tjrwodnjs999 | Jakarta Skyscrapers (APIO15_skyscraper) | C++11 | 3 ms | 2028 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];
ll dist[30005];
vector<int> Map[30005],adj[30005],vt[10][10];
priority_queue<pair<ll,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<10;j++) vt[j][B[i]%j].push_back(i);
}
for(int i=1;i<=m;i++){
if(P[i]>=10){
for(int j:Map[B[i]]) if(j!=i) adj[i].push_back(j);
for(int j=B[i]+P[i];j<n;j++){
for(int k:Map[j]) adj[i].push_back(k);
}
for(int j=B[i]-P[i];j>=0;j--){
for(int k:Map[j]) adj[i].push_back(k);
}
}
}
fill(dist,dist+30005,1e9);
dist[1]=0; pq.push({0,1});
while(!pq.empty()){
int now=pq.top().second;
ll cost=-pq.top().first; pq.pop();
if(dist[now]<cost) continue;
if(P[now]>=10){
for(int i:adj[now]){
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("%lld",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... |