# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
334951 | Saynaa | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 1095 ms | 9448 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;
typedef long long ll;
const int MAXN = 3e5 + 2;
int n, m, b[MAXN], p[MAXN], dis[MAXN], v, tmp, u, x;
vector< int > adj[MAXN];
int main(){
scanf("%d%d", &n, &m);
for(int i = 0; i < m; i ++){
scanf("%d%d", &b[i], &p[i]);
adj[b[i]].push_back(p[i]);
}
for(int i = 0;i < n; i ++) dis[i] = INT_MAX;
dis[b[0]] = 0;
priority_queue< pair< int, int> > q;
q.push({0, b[0]});
while( q.size() ){
v = q.top().second, tmp = -q.top().first;
q.pop();
if( dis[v] < tmp || dis[v] == INT_MAX) continue;
for(int i = 0; i < adj[v].size(); i ++){
u = adj[v][i];
x = 1;
for(int i = v + u; i < n; i += u){
if( dis[i] <= dis[v] + x){
x ++;
continue;
}
dis[i] = dis[v] + x, q.push({-dis[i], i}), x ++;
}
x = 1;
for(int i = v - u; i >= 0; i -= u){
if( dis[i] <= dis[v] + x){
x ++;
continue;
}
dis[i] = dis[v] + x, q.push({-dis[i], i}), x ++;
}
}
}
if( dis[b[1]] == INT_MAX) return printf("%d", -1), 0;
printf("%d",dis[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... |