#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 - 1 - T[j] + 1 + from[mid][V[j]];
answer[j] = min(answer[j], dist);
}
}
}
vector<array<ll, 3>> 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], ~j, x});
}
for (int i = 0; i < m; ++i) {
if (till[x][i] >= 0) {
events.push_back({till[x][i], i, x});
}
}
}
sort(events.rbegin(), events.rend());
for (int i = 0; i < n; ++i) {
siz[i] = 1;
memset(dp[i][0], 0x3f, sizeof(dp[i][0]));
moment[i][0] = inf;
dp[i][0][i] = 0;
}
auto distQuery = [&](int x, ll t) {
int r = upper_bound(moment[x], moment[x] + siz[x], t, greater<>()) - moment[x];
return r - 1;
};
for (auto [ti, 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;
}
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];
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 time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
64980 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1287 ms |
193544 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
64980 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
64980 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
64980 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |