이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "escape_route.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
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) {
vector<ll> answer(q);
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);
}
constexpr ll inf = 3e18;
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));
for (int i = 0; i < n; ++i) {
from[i] = dijkstra(i, 0);
}
vector dto(n, vector<ll>(n));
for (int i = 0; i < n; ++i) {
dto[i] = dijkstra(i, S - 1, true);
}
vector most(n, vector<ll>(n));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i == j) {
most[i][j] = inf;
continue;
}
ll lo = -1, hi = S;
while (lo + 1 < hi) {
ll mid = (lo + hi) / 2;
if (mid + dijkstra(i, mid)[j] < S) {
lo = mid;
} else {
hi = mid;
}
}
most[i][j] = lo;
}
}
for (int i = 0; i < n; ++i) {
vector<ll> till;
vector<vector<ll>> dp;
int dead = 0;
for (int j = 0; dead < m; ++j) {
till.push_back(0);
dp.emplace_back();
ll s = j > 0 ? till[j - 1] + 1 : 0;
dead = 0;
if (s < S) {
vector<ll> d = dijkstra(i, s);
for (int to = 0; to < n; ++to) {
if (d[to] + s >= S) {
d[to] = inf;
}
}
dp[j] = d;
ll nxt = inf;
for (int k = 0; k < m; ++k) {
if (d[A[k]] > d[B[k]]) {
swap(A[k], B[k]);
}
if (C[k] - L[k] >= d[A[k]]) {
nxt = min(nxt, C[k] - L[k] - d[A[k]]);
} else {
dead += 1;
}
}
till[j] = s + nxt;
} else {
dp[j] = vector(n, inf);
till[j] = inf;
dead = m;
}
}
for (int j : queries[i]) {
ll ans = inf;
int to = V[j];
for (int mid = 0; mid < n; ++mid) {
ll dist = most[i][mid] < T[j] ? inf : S - 1 - T[j] + 1 + from[mid][to];
ans = min(ans, dist);
}
int k = lower_bound(till.begin(), till.end(), T[j]) - till.begin();
if (k < dp.size()) {
ans = min(ans, dp[k][to]);
}
answer[j] = ans;
}
}
return answer;
}
컴파일 시 표준 에러 (stderr) 메시지
escape_route.cpp: In function 'std::vector<long long int> calculate_necessary_time(int, int, ll, int, std::vector<int>, std::vector<int>, std::vector<long long int>, std::vector<long long int>, std::vector<int>, std::vector<int>, std::vector<long long int>)':
escape_route.cpp:159:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<long long int>, std::allocator<std::vector<long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
159 | if (k < dp.size()) {
| ~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |