Submission #410192

#TimeUsernameProblemLanguageResultExecution timeMemory
410192jeqchoJakarta Skyscrapers (APIO15_skyscraper)C++17
22 / 100
85 ms127832 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 N=3e4+3; int const sN=174+3; int const M=3e4+3; int b[M]; int p[M]; int d[N][sN]; int const INF=1e9; bitset<sN> vis[N]; vi doges[N]; vector<pair<pii,int>>adj[N][sN]; 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); if(p[i]>=sN) { int nxt=b[i]+p[i]; int cnt=1; while(nxt<n) { adj[b[i]][0].pb({{nxt,0},cnt}); ++cnt; nxt+=p[i]; } nxt=b[i]-p[i]; cnt=1; while(nxt>=0) { adj[b[i]][0].pb({{nxt,0},cnt}); ++cnt; nxt-=p[i]; } } else { adj[b[i]][0].pb({{b[i],p[i]},0}); } } F0R(i,n) { fill(d[i],d[i]+sN,INF); } priority_queue<pair<int,pii>> q; d[b[0]][0]=0; q.push({0,{b[0],0}}); while(!q.empty()) { int pos = q.top().se.fi; int pw = q.top().se.se; q.pop(); if(vis[pos][pw])continue; vis[pos][pw]=1; if(pw==0) { trav(doge,doges[pos]) { adj[pos][pw].pb({{pos,p[doge]},0}); } } else { int nxt=pos+pw; if(nxt<n) { adj[pos][pw].pb({{nxt,pw},1}); adj[pos][pw].pb({{nxt,0},1}); } nxt=pos-pw; if(nxt>=0) { adj[pos][pw].pb({{nxt,pw},1}); adj[pos][pw].pb({{nxt,0},1}); } } trav(e,adj[pos][pw]) { int cand = d[pos][pw]+e.se; if(cand<d[e.fi.fi][e.fi.se]) { d[e.fi.fi][e.fi.se]=cand; q.push({-cand,e.fi}); } } adj[pos][pw].clear(); } if(d[b[1]][0]==INF)cout<<-1<<'\n'; else cout<<d[b[1]][0]<<'\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...