제출 #410114

#제출 시각아이디문제언어결과실행 시간메모리
410114jeqchoJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1089 ms3496 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 far[M]; 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; fill(far,far+m,0); while(!q.empty() && (!vis[b[1]])) { int u=q.top().se; q.pop(); bool go=0; if(q.empty()) { go=1; } else if(vis[u]) { continue; } vis[u]=1; visited.pb(u); bool ok=1; while(go&&ok) { ++mxjump; ok=0; trav(e,visited) { trav(doge,doges[e]) { while(d[e]+far[doge]<mxjump) { ++far[doge]; int nxt = e + p[doge]*far[doge]; int cand = d[e]+far[doge]; if(nxt<n) { ok=1; if(cand<d[nxt]) { d[nxt]=cand; go=0; q.push({-cand,nxt}); } } nxt = e - p[doge]*far[doge]; if(nxt>=0) { ok=1; if(cand<d[nxt]) { d[nxt]=cand; go=0; 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...