Submission #410182

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