Submission #422061

#TimeUsernameProblemLanguageResultExecution timeMemory
422061lycEscape Route (JOI21_escape_route)C++17
5 / 100
9047 ms112012 KiB
#include "escape_route.h" #include <bits/stdc++.h> using namespace std; #define TRACE(x) cerr << #x << " :: " << x << endl #define _ << " " << #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(),(x).end() #define FOR(i,a,b) for(int i=(a);i<=(b);++i) #define RFOR(i,a,b) for(int i=(a);i>=(b);--i) const int mxN = 90; typedef long long ll; struct Edge { int v; ll l, c; }; int N; ll S; vector<Edge> al[mxN]; pair<bitset<mxN>, vector<ll>> dijkstra(int s, ll t) { bitset<mxN> vis; vis.reset(); vector<ll> dist(N,S+1); priority_queue<pair<ll,int>> pq; pq.push(make_pair(0,s)); dist[s] = 0; while (!pq.empty()) { int u = pq.top().second; ll w = -pq.top().first; pq.pop(); vis[u] = 1; if (w > dist[u]) continue; for (auto& e : al[u]) { if (t+w+e.l <= e.c && w+e.l <= dist[e.v]) { dist[e.v] = w+e.l; pq.push(make_pair(-dist[e.v],e.v)); } } } return make_pair(vis,dist); } map<ll, pair<bitset<mxN>, vector<ll>>> bounds[mxN]; bitset<mxN> ok[mxN][mxN]; vector<ll> zdist[mxN]; std::vector<long long> calculate_necessary_time( int _N, int M, long long _S, int Q, std::vector<int> A, std::vector<int> B, std::vector<long long> L, std::vector<long long> C, std::vector<int> U, std::vector<int> V, std::vector<long long> T) { N = _N; S = _S; FOR(i,0,M-1){ al[A[i]].push_back({B[i],L[i],C[i]}); al[B[i]].push_back({A[i],L[i],C[i]}); } FOR(i,0,N-1){ auto prv = dijkstra(i,0); ok[i][0] = prv.first; zdist[i] = prv.second; bounds[i][0] = prv; ll lo = 0, hi = S+1; while (true) { while (hi-lo > 1) { ll mid = (lo+hi)/2; auto cur = dijkstra(i,mid); if (prv.second == cur.second) lo = mid; else hi = mid; } prv = dijkstra(i,hi); bounds[i][hi] = prv; //cout << i _ hi << ": "; //FOR(j,0,N-1){ cout << prv.second[j] << ' '; } cout << endl; if (prv.first.count() == 1) break; lo = hi; hi = S+1; } } FOR(k,1,6){ FOR(i,0,N-1){ ok[i][k].reset(); FOR(j,0,N-1) if (ok[i][k-1][j]) { ok[i][k] |= ok[j][k-1]; } } } vector<ll> ans(Q); FOR(i,0,Q-1){ auto it = (--bounds[U[i]].lower_bound(T[i]+1)); auto st = it->second.first; auto d = it->second.second; //TRACE(i _ it->first _ SZ(d)); if (st[V[i]]) { ans[i] = d[V[i]]; } else { ans[i] = S - T[i]; RFOR(k,6,0){ bitset<mxN> tmp; tmp.reset(); FOR(j,0,N-1) if (st[j]) { tmp |= ok[j][k]; } if (!tmp[V[i]]) { st |= tmp; ans[i] += (1<<k) * S; } } ll mn = S+1; FOR(j,0,N-1) if (st[j]) { mn = min(mn, zdist[j][V[i]]); } //TRACE( i _ ans[i] _ mn ); ans[i] += mn; } } return ans; }
#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...