Submission #410139

#TimeUsernameProblemLanguageResultExecution timeMemory
410139jeqchoJakarta Skyscrapers (APIO15_skyscraper)C++17
10 / 100
2 ms2004 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; bitset<N> vis; int d[N]; int const INF=1e9; unordered_set<int> doges[N]; unordered_set<int> visited; int far[M]; // subtask 1,2,3,4 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]].insert(i); } fill(d,d+n,INF); d[b[0]]=0; fill(far,far+n,0); visited.insert(b[0]); while(!visited.empty()) { vi dead; vi nw; trav(place,visited) { ++far[place]; vi rem; trav(doge,doges[place]) { int nxt = place + p[doge]*far[place]; bool ok=0; if(nxt<n) { ok=1; if(!vis[nxt]) { vis[nxt]=1; nw.pb(nxt); d[nxt]=d[place]+far[place]; } } nxt = place - p[doge]*far[place]; if(nxt>=0) { ok=1; if(!vis[nxt]) { vis[nxt]=1; nw.pb(nxt); d[nxt]=d[place]+far[place]; } } if(!ok) { rem.pb(doge); } } trav(doge,rem) { doges[place].erase(doge); } if(doges[place].empty()) { dead.pb(place); } } trav(k,dead) { visited.erase(k); } trav(k,nw) { visited.insert(k); } } 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...