Submission #410108

#TimeUsernameProblemLanguageResultExecution timeMemory
410108jeqchoJakarta Skyscrapers (APIO15_skyscraper)C++17
0 / 100
2 ms1740 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<pair<int,int>> vpi; #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define trav(a,x) for (auto& a: x) #define pb push_back #define rsz resize #define sz(x) int(x.size()) #define all(x) begin(x), end(x) #define fi first #define se second int const M=3e4+3; int b[M],p[M]; int const N=3e4+3; vpi adj[N]; bitset<N> vis; int d[N]; int const INF=1e9; vi doges[N]; vi visited; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,m; cin>>n>>m; F0R(i,m) { cin>>b[i]>>p[i]; doges[b[i]].pb(i); } int mxjump=0; priority_queue<pii> q; q.push({0,b[0]}); fill(d,d+n,INF); d[b[0]]=0; while(!q.empty() && (!vis[b[1]])) { int u=q.top().se; q.pop(); if(vis[u])continue; vis[u]=1; visited.pb(u); if(d[u]==mxjump) { ++mxjump; trav(e,visited) { trav(doge,doges[e]) { int cand = d[e]+mxjump; int nxt = e+p[doge]*mxjump; if(nxt<n && cand < d[nxt]) { d[nxt] = cand; q.push({-cand,nxt}); } nxt = e-p[doge]*mxjump; if(nxt>=0 && cand < d[nxt]) { d[nxt] = cand; q.push({-cand,nxt}); } } } } } if(d[b[1]]==INF)cout<<-1<<'\n'; else cout<<d[b[1]]<<'\n'; return 0; }
#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...