답안 #634039

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
634039 2022-08-23T17:50:23 Z valerikk Escape Route (JOI21_escape_route) C++17
100 / 100
3495 ms 171888 KB
#include "escape_route.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll INF = 1e18;

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) {

	for (int i = 0; i < m; ++i) {
		A.push_back(B[i]);
		B.push_back(A[i]);
		L.push_back(L[i]);
		C.push_back(C[i]);
	}
	m = A.size();

	vector<vector<int>> g(n);
	for (int i = 0; i < m; ++i) {
		g[A[i]].push_back(i);
	}

	auto dijkstra = [&](int s, ll t) {
		vector<ll> d(n, INF);
		d[s] = t;
		vector<bool> used(n, false);
		for (int it = 0; it < n; ++it) {
			int u = -1;
			for (int i = 0; i < n; ++i) {
				if (!used[i] && (u == -1 || d[i] < d[u])) {
					u = i;
				}
			}
			if (d[u] == INF) break;
			used[u] = true;
			for (int e : g[u]) {
				int v = B[e];
				ll cur = d[u] + L[e];
				if (d[u] % S + L[e] > C[e]) cur += S - d[u] % S;
				d[v] = min(d[v], cur);
			}
		}
		return d;
	};

	vector<vector<ll>> dist0(n);
	for (int i = 0; i < n; ++i) {
		dist0[i] = dijkstra(i, 0);
	}
	vector<vector<ll>> dist_edge(m);
	for (int i = 0; i < m; ++i) {
		dist_edge[i] = dijkstra(A[i], C[i] - L[i]);
		for (int v = 0; v < n; ++v) {
			if (dist_edge[i][v] <= S) {
				dist_edge[i][v] -= C[i] - L[i];
			} else {
				dist_edge[i][v] = INF;
			}
		}
	}

	vector<ll> ans(Q);
	for (int i = 0; i < Q; ++i) {
		ans[i] = (S - T[i]) % S + dist0[U[i]][V[i]];
	}

	for (int i = 0; i < n; ++i) {
		sort(g[i].begin(), g[i].end(), [&](int ei, int ej) {
			return C[ei] - L[ei] > C[ej] - L[ej];
		});
	}

	for (int s = 0; s < n; ++s) {
		vector<int> queries;
		for (int i = 0; i < Q; ++i) {
			if (U[i] == s) {
				queries.push_back(i);
			}
		}
		sort(queries.begin(), queries.end(), [&](int i, int j) {
			return T[i] > T[j];
		});
		int qind = 0;
		vector<int> ind(n, 0);
		vector<ll> d(n, INF);
		d[s] = 0;
		while (true) {
			pair<ll, int> mx = {-1, -1};
			for (int u = 0; u < n; ++u) {
				if (ind[u] < (int)g[u].size()) {
					int e = g[u][ind[u]];
					mx = max(mx, {C[e] - L[e] - d[u], u});
				}
			}
			while (qind < (int)queries.size() && T[queries[qind]] > mx.first) {
				int i = queries[qind++];
				ans[i] = min(ans[i], d[V[i]]);
				for (int u = 0; u < n; ++u) {
					if (d[u] < INF) {
						ans[i] = min(ans[i], S - T[i] + dist0[u][V[i]]);
					}
				}
			}
			if (mx.first < 0) break;
			int e = g[mx.second][ind[mx.second]++];
			for (int i = 0; i < n; ++i) {
				if (dist_edge[e][i] < INF) {
					d[i] = min(d[i], dist_edge[e][i] + d[mx.second]);
				}
			}
		}
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 65000 KB Output is correct
2 Correct 31 ms 64980 KB Output is correct
3 Correct 66 ms 65036 KB Output is correct
4 Correct 26 ms 65000 KB Output is correct
5 Correct 45 ms 65004 KB Output is correct
6 Correct 25 ms 64980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1664 ms 114468 KB Output is correct
2 Correct 1947 ms 123780 KB Output is correct
3 Correct 1801 ms 114052 KB Output is correct
4 Correct 1787 ms 123992 KB Output is correct
5 Correct 1759 ms 124200 KB Output is correct
6 Correct 25 ms 64980 KB Output is correct
7 Correct 1668 ms 115220 KB Output is correct
8 Correct 1646 ms 138676 KB Output is correct
9 Correct 1611 ms 115128 KB Output is correct
10 Correct 1735 ms 125904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 65000 KB Output is correct
2 Correct 31 ms 64980 KB Output is correct
3 Correct 66 ms 65036 KB Output is correct
4 Correct 26 ms 65000 KB Output is correct
5 Correct 45 ms 65004 KB Output is correct
6 Correct 25 ms 64980 KB Output is correct
7 Correct 1664 ms 114468 KB Output is correct
8 Correct 1947 ms 123780 KB Output is correct
9 Correct 1801 ms 114052 KB Output is correct
10 Correct 1787 ms 123992 KB Output is correct
11 Correct 1759 ms 124200 KB Output is correct
12 Correct 25 ms 64980 KB Output is correct
13 Correct 1668 ms 115220 KB Output is correct
14 Correct 1646 ms 138676 KB Output is correct
15 Correct 1611 ms 115128 KB Output is correct
16 Correct 1735 ms 125904 KB Output is correct
17 Correct 1593 ms 157024 KB Output is correct
18 Correct 1560 ms 156876 KB Output is correct
19 Correct 1676 ms 156332 KB Output is correct
20 Correct 1647 ms 156400 KB Output is correct
21 Correct 1680 ms 162600 KB Output is correct
22 Correct 1700 ms 161680 KB Output is correct
23 Correct 1605 ms 139640 KB Output is correct
24 Correct 1613 ms 171888 KB Output is correct
25 Correct 1565 ms 137668 KB Output is correct
26 Correct 1802 ms 156924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 65000 KB Output is correct
2 Correct 31 ms 64980 KB Output is correct
3 Correct 66 ms 65036 KB Output is correct
4 Correct 26 ms 65000 KB Output is correct
5 Correct 45 ms 65004 KB Output is correct
6 Correct 25 ms 64980 KB Output is correct
7 Correct 1664 ms 114468 KB Output is correct
8 Correct 1947 ms 123780 KB Output is correct
9 Correct 1801 ms 114052 KB Output is correct
10 Correct 1787 ms 123992 KB Output is correct
11 Correct 1759 ms 124200 KB Output is correct
12 Correct 25 ms 64980 KB Output is correct
13 Correct 1668 ms 115220 KB Output is correct
14 Correct 1646 ms 138676 KB Output is correct
15 Correct 1611 ms 115128 KB Output is correct
16 Correct 1735 ms 125904 KB Output is correct
17 Correct 1593 ms 157024 KB Output is correct
18 Correct 1560 ms 156876 KB Output is correct
19 Correct 1676 ms 156332 KB Output is correct
20 Correct 1647 ms 156400 KB Output is correct
21 Correct 1680 ms 162600 KB Output is correct
22 Correct 1700 ms 161680 KB Output is correct
23 Correct 1605 ms 139640 KB Output is correct
24 Correct 1613 ms 171888 KB Output is correct
25 Correct 1565 ms 137668 KB Output is correct
26 Correct 1802 ms 156924 KB Output is correct
27 Correct 2139 ms 136672 KB Output is correct
28 Correct 2145 ms 135788 KB Output is correct
29 Correct 2009 ms 150376 KB Output is correct
30 Correct 1990 ms 134072 KB Output is correct
31 Correct 2111 ms 155344 KB Output is correct
32 Correct 2045 ms 153916 KB Output is correct
33 Correct 1790 ms 162760 KB Output is correct
34 Correct 1942 ms 129392 KB Output is correct
35 Correct 2089 ms 147188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 65000 KB Output is correct
2 Correct 31 ms 64980 KB Output is correct
3 Correct 66 ms 65036 KB Output is correct
4 Correct 26 ms 65000 KB Output is correct
5 Correct 45 ms 65004 KB Output is correct
6 Correct 25 ms 64980 KB Output is correct
7 Correct 1664 ms 114468 KB Output is correct
8 Correct 1947 ms 123780 KB Output is correct
9 Correct 1801 ms 114052 KB Output is correct
10 Correct 1787 ms 123992 KB Output is correct
11 Correct 1759 ms 124200 KB Output is correct
12 Correct 25 ms 64980 KB Output is correct
13 Correct 1668 ms 115220 KB Output is correct
14 Correct 1646 ms 138676 KB Output is correct
15 Correct 1611 ms 115128 KB Output is correct
16 Correct 1735 ms 125904 KB Output is correct
17 Correct 1593 ms 157024 KB Output is correct
18 Correct 1560 ms 156876 KB Output is correct
19 Correct 1676 ms 156332 KB Output is correct
20 Correct 1647 ms 156400 KB Output is correct
21 Correct 1680 ms 162600 KB Output is correct
22 Correct 1700 ms 161680 KB Output is correct
23 Correct 1605 ms 139640 KB Output is correct
24 Correct 1613 ms 171888 KB Output is correct
25 Correct 1565 ms 137668 KB Output is correct
26 Correct 1802 ms 156924 KB Output is correct
27 Correct 2139 ms 136672 KB Output is correct
28 Correct 2145 ms 135788 KB Output is correct
29 Correct 2009 ms 150376 KB Output is correct
30 Correct 1990 ms 134072 KB Output is correct
31 Correct 2111 ms 155344 KB Output is correct
32 Correct 2045 ms 153916 KB Output is correct
33 Correct 1790 ms 162760 KB Output is correct
34 Correct 1942 ms 129392 KB Output is correct
35 Correct 2089 ms 147188 KB Output is correct
36 Correct 3417 ms 128172 KB Output is correct
37 Correct 3445 ms 126540 KB Output is correct
38 Correct 3392 ms 129332 KB Output is correct
39 Correct 3495 ms 143424 KB Output is correct
40 Correct 3474 ms 140760 KB Output is correct
41 Correct 2060 ms 145136 KB Output is correct
42 Correct 3324 ms 116544 KB Output is correct
43 Correct 3352 ms 115556 KB Output is correct