Submission #15878

#TimeUsernameProblemLanguageResultExecution timeMemory
15878myungwooJakarta Skyscrapers (APIO15_skyscraper)C++14
100 / 100
85 ms11656 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 30005 #define pb push_back #define mp make_pair typedef pair<int, int> pii; int N, M, S, E; int D[MAXN]; bool V[MAXN][200]; vector <int> doge[MAXN]; int main() { scanf("%d%d", &N, &M); for (int i=0;i<M;i++){ int b, p; scanf("%d%d", &b, &p); if (p > 199 || !V[b][p]) doge[b].pb(p); if (p < 200) V[b][p] = 1; if (!i) S = b; if (i == 1) E = b; } for (int i=0;i<N;i++) D[i] = 2e9; priority_queue <pii> que; D[S] = 0; que.push(mp(0, S)); while (!que.empty()){ int q = que.top().second, d = -que.top().first; que.pop(); if (D[q] != d) continue; for (int p: doge[q]){ for (int i=q-p;i>=0;i-=p){ if (D[i] > d+(q-i)/p) D[i] = d+(q-i)/p, que.push(mp(-D[i], i)); if (p < 200 && V[i][p]) break; if (p < 200) V[i][p] = 1; } for (int i=q+p;i<N;i+=p){ if (D[i] > d+(i-q)/p) D[i] = d+(i-q)/p, que.push(mp(-D[i], i)); if (p < 200 && V[i][p]) break; if (p < 200) V[i][p] = 1; } } } printf("%d\n", D[E] < 2e9 ? D[E] : -1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...