# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
334947 | Saynaa | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 1091 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];
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]);
}
fill(dis, dis + n, INT_MAX/2);
dis[b[0]] = 0;
priority_queue< pair< int, int> > q;
q.push({0, b[0]});
while( q.size() ){
int v = q.top().second, tmp = -q.top().first;
q.pop();
if( dis[v] < tmp || dis[v] == INT_MAX/2) continue;
for(int i = 0; i < adj[v].size(); i ++){
int u = adj[v][i];
int x = 1;
for(int i = v + u; i < n; i += u){
x ++;
if( dis[i] <= dis[v] + x - 1)
continue;
dis[i] = dis[v] + x - 1, q.push({-dis[i], i});
}
x = 1;
for(int i = v - u; i >= 0; i -= u){
x ++;
if( dis[i] <= dis[v] + x - 1)
continue;
dis[i] = dis[v] + x - 1, q.push({-dis[i], i});
}
}
}
printf("%d", (dis[b[1]] != INT_MAX/2 ? dis[b[1]] : -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... |