# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
133543 | junodeveloper | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 291 ms | 68196 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 sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
int n,m;
int B[30010],P[30010],D[30010];
set<int> ps[30010];
vector<pi> adj[30010];
int main() {
scanf("%d%d",&n,&m);
int i,j;
for(i=0;i<m;i++) {
scanf("%d%d", B+i, P+i);
ps[B[i]].insert(P[i]);
}
for(i=0;i<n;i++) {
int cur;
for(auto& it:ps[i]) {
cur=i-it;
while(cur>=0) {
adj[i].push_back({cur,(i-cur)/it});
if(ps[cur].find(it)!=ps[cur].end()) break;
cur-=it;
}
cur=i+it;
while(cur<n) {
adj[i].push_back({cur,(cur-i)/it});
if(ps[cur].find(it)!=ps[cur].end()) break;
cur+=it;
}
}
}
fill(D,D+n,(int)1e9);
priority_queue<pi,vector<pi>,greater<pi> > pq;
pq.push({0,B[0]}); D[B[0]]=0;
while(!pq.empty()) {
int w,u; tie(w,u)=pq.top(); pq.pop();
if(D[u]<w) continue;
if(u==B[1]) break;
for(auto& it:adj[u]) {
if(w+it.se<D[it.fi]) {
D[it.fi]=w+it.se;
pq.push({D[it.fi],it.fi});
}
}
}
printf("%d\n", D[B[1]]==(int)1e9?-1:D[B[1]]);
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... |