Submission #410135

#TimeUsernameProblemLanguageResultExecution timeMemory
410135jeqchoJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1088 ms7772 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; 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); } 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.insert(u); bool ok=1; while(go&&ok) { ok=0; vi dead; trav(e,visited) { vi rem; trav(doge,doges[e]) { bool cur=0; ++far[doge]; int nxt = e + p[doge]*far[doge]; int cand = d[e]+far[doge]; if(nxt<n) { cur=1; ok=1; if(cand<d[nxt]) { d[nxt]=cand; go=0; q.push({-cand,nxt}); } } nxt = e - p[doge]*far[doge]; if(nxt>=0) { cur=1; ok=1; if(cand<d[nxt]) { d[nxt]=cand; go=0; q.push({-cand,nxt}); } } if(!cur) { rem.pb(doge); } } trav(doge,rem) { doges[e].erase(doge); } if(doges[e].empty()) { dead.pb(e); } } trav(place,dead) { visited.erase(place); } } } 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...