# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
158241 | Akashi | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 260 ms | 65636 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;
int sgn[] = {-1, 1};
int n, m, pos;
int d[30005];
bool viz[30005];
set <int> s[30005];
vector <pair <int, int> > v[30005];
priority_queue <pair <int, int>, vector <pair <int, int> >, greater <pair <int, int> > > q;
int main()
{
scanf("%d%d", &n, &m);
int x2, x, y;
scanf("%d%d", &x, &y);
s[x].insert(y); x2 = x;
scanf("%d%d", &x, &y);
pos = x;
if(pos == x2){
printf("0");
return 0;
}
for(int i = 3; i <= m ; ++i){
scanf("%d%d", &x, &y);
s[x].insert(y);
}
for(int i = 0; i < n ; ++i){
d[i] = 1e9;
if(s[i].empty()) continue ;
for(auto it : s[i]){
int nod = i, x = i, y = it, k = 1;
while(x + y < n){
v[nod].push_back({x + y, k});
x += y; ++k;
if(s[x].find(y) != s[x].end()) break ;
}
x = i; k = 1;
while(x - y >= 0){
v[nod].push_back({x - y, k});
x -= y; ++k;
if(s[x].find(y) != s[x].end()) break ;
}
}
}
q.push({0, x2});
d[x2] = 0;
while(!q.empty()){
int l = q.top().first, nod = q.top().second;
if(pos == nod){
printf("%d", l);
return 0;
}
q.pop();
if(viz[nod]) continue ;
viz[nod] = 1;
for(auto it : v[nod]){
if(d[it.first] > l + it.second){
d[it.first] = l + it.second;
q.push({l + it.second, it.first});
}
}
}
printf("-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... |