Submission #410156

#TimeUsernameProblemLanguageResultExecution timeMemory
410156jeqchoJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1094 ms9784 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; set<int> skills[N]; int far[N]; bitset<M> lefded; bitset<M> rigded; // 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); skills[b[i]].insert(p[i]); } fill(d,d+n,INF); d[b[0]]=0; fill(far,far+n,0); visited.insert(b[0]); vis[b[0]]=1; 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(!rigded[doge]&&nxt<n) { ok=1; if(!vis[nxt]) { vis[nxt]=1; nw.pb(nxt); d[nxt]=d[place]+far[place]; } else if(skills[nxt].find(b[doge])!=skills[nxt].end()) { rigded[doge]=1; } } 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]; } else if(skills[nxt].find(b[doge])!=skills[nxt].end()) { lefded[doge]=1; } } if((!ok)||(lefded[doge]&&rigded[doge])) { 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...