제출 #723697

#제출 시각아이디문제언어결과실행 시간메모리
723697piOOEEscape Route (JOI21_escape_route)C++17
0 / 100
1232 ms216600 KiB
#include "escape_route.h" #include <bits/stdc++.h> using namespace std; using ll = long long; constexpr int N = 91; ll dp[N][N * N][N], moment[N][N]; int siz[N]; vector<ll> calculate_necessary_time(int n, int m, ll S, int q, vector<int> A, vector<int> B, vector<ll> L, vector<ll> C, vector<int> U, vector<int> V, vector<ll> T) { constexpr ll inf = 3e18; vector<ll> answer(q, inf); vector<vector<int>> queries(n); for (int i = 0; i < q; ++i) { queries[U[i]].push_back(i); } vector<vector<pair<int, int>>> adj(n); for (int i = 0; i < m; ++i) { adj[A[i]].emplace_back(B[i], i); adj[B[i]].emplace_back(A[i], i); } auto dijkstra = [&](int source, ll s, bool rev = false) -> vector<ll> { vector<ll> dist(n, rev ? -inf : inf); dist[source] = s; vector<bool> used(n); for (int _ = 0; _ < n; ++_) { int v = -1; for (int i = 0; i < n; ++i) { if (!used[i] && (v == -1 || rev ^ (dist[i] < dist[v]))) { v = i; } } used[v] = true; for (auto [to, i] : adj[v]) { ll d; if (rev) { d = min(dist[v], C[i]) - L[i]; } else { d = L[i] + (dist[v] % S <= C[i] - L[i] ? dist[v] : (dist[v] / S + 1) * S); } if (rev ^ (dist[to] > d)) { dist[to] = d; } } } for (int i = 0; i < n; ++i) { dist[i] = rev ? s - dist[i] : dist[i] - s; } return dist; }; vector from(n, vector<ll>(n)), dto(n, vector<ll>(n)); for (int i = 0; i < n; ++i) { from[i] = dijkstra(i, 0); } for (int i = 0; i < n; ++i) { dto[i] = dijkstra(i, S - 1, true); } for (int i = 0; i < n; ++i) { for (int j : queries[i]) { for (int mid = 0; mid < n; ++mid) { ll dist = S - 1 - dto[mid][i] < T[j] ? inf : S - T[j] + from[mid][V[j]]; answer[j] = min(answer[j], dist); } } } vector<array<ll, 4>> events; //time, idx (if query then ~), x vector till(n, vector<ll>(m, -inf)); for (int i = 0; i < m; ++i) { int a = A[i], b = B[i]; ll t = C[i] - L[i]; auto da = dijkstra(a, t, true); auto db = dijkstra(b, t, true); for (int x = 0; x < n; ++x) { da[x] = t >= da[x] ? t - da[x] : -inf; db[x] = t >= db[x] ? t - db[x] : -inf; till[x][i] = max(da[x], db[x]); } } for (int x = 0; x < n; ++x) { for (int j : queries[x]) { events.push_back({T[j], -inf, ~j, x}); } for (int i = 0; i < m; ++i) { if (till[x][i] >= 0) { events.push_back({till[x][i], -C[i], i, x}); } } } sort(events.rbegin(), events.rend()); for (int i = 0; i < n; ++i) { siz[i] = 1; fill_n(dp[i][0], n, inf); dp[i][0][i] = 0; moment[i][0] = inf; } auto distQuery = [&](int x, ll t) { int r = upper_bound(moment[x], moment[x] + siz[x], t, greater<>()) - moment[x]; assert(r != 0 && (r == siz[x] || moment[x][r] < t) && moment[x][r - 1] >= t); return r - 1; }; for (auto [ti, useless, j, x] : events) { if (j < 0) { j = ~j; ll d = dp[x][siz[x] - 1][V[j]]; if (T[j] + d < S) { answer[j] = min(answer[j], d); } continue; } if (ti < 0) { break; } memcpy(dp[x][siz[x]], dp[x][siz[x] - 1], sizeof(dp[x][siz[x]])); moment[x][siz[x]] = ti; int a = A[j], b = B[j]; if (dp[x][siz[x] - 1][a] > dp[x][siz[x] - 1][b]) { swap(a, b); } ll distB = dp[x][siz[x] - 1][a] + L[j]; // cout << x << " " << j << endl; assert(ti + distB <= C[j]); if (distB < dp[x][siz[x] - 1][b]) { int r = distQuery(b, distB); for (int to = 0; to < n; ++to) { dp[x][siz[x]][to] = min(dp[x][siz[x]][to], dp[b][r][to] + distB); } } siz[x] += 1; } return answer; }
#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...