Submission #634035

# Submission time Handle Problem Language Result Execution time Memory
634035 2022-08-23T17:47:24 Z valerikk Escape Route (JOI21_escape_route) C++17
100 / 100
2959 ms 193780 KB
#include "escape_route.h"
#include <algorithm>
#include <iostream>
 
using std::vector;
using std::pair;
 
using ll = long long;
 
const ll INF = 1e18;
 
vector<ll> dijkstra(int N, ll S, int st, ll T, vector<vector<ll>> &l, vector<vector<ll>> &c) {
	vector<ll> t(N, INF);
	vector<bool> used(N, 0);
	t[st] = T;
	for (int it = 0; it < N; ++it) {
		int u = -1;
		for (int i = 0; i < N; ++i) {
			if (!used[i] && (u == -1 || t[i] < t[u]))
				u = i;
		}
		if (t[u] == INF) break;
		used[u] = 1;
		for (int v = 0; v < N; ++v) {
			if (!used[v] && l[u][v] < S) {
				ll t1 = t[u] + l[u][v];
				if (t[u] % S + l[u][v] > c[u][v]) 
					t1 += S - t[u] % S;
				t[v] = std::min(t[v], t1);
			}
		}
	}
	return t;
}
 
vector<long long> calculate_necessary_time(
	int N, int M, long long S, int Q, vector<int> A, vector<int> B,
	vector<long long> L, vector<long long> C, vector<int> U,
	vector<int> V, vector<long long> T) {
	
	vector<vector<ll>> l(N, vector<ll>(N, S));
	vector<vector<ll>> c(N, vector<ll>(N, S));
	for (int i = 0; i < M; ++i) {
		l[A[i]][B[i]] = l[B[i]][A[i]] = L[i];
		c[A[i]][B[i]] = c[B[i]][A[i]] = C[i];
	}
	for (int i = 0; i < N; ++i) {
		l[i][i] = 0;
		c[i][i] = 0;
	}
	vector<vector<vector<ll>>> t(N, vector<vector<ll>>(N));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			if (l[i][j] < S) 
				t[i][j] = dijkstra(N, S, j, c[i][j], l, c);
		}
	}
	vector<ll> ans(Q);
	for (int i = 0; i < Q; ++i) {
		ans[i] = t[U[i]][U[i]][V[i]] + (S - T[i]) % S;
	}
	for (int st = 0; st < N; ++st) {
		vector<pair<ll, int>> que;
		for (int i = 0; i < Q; ++i) {
			if (U[i] == st) 
				que.push_back({T[i], i});
		}
		std::sort(que.rbegin(), que.rend());
		vector<vector<pair<ll, int>>> ord(N);
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				if (i != j && l[i][j] < S) 
					ord[i].push_back({c[i][j] - l[i][j], j});
			}
			std::sort(ord[i].rbegin(), ord[i].rend());
		}
		vector<int> ind(N, 0);
		vector<ll> d(N, INF);
		d[st] = 0;
		int ptr = 0;
		while (1) {		
			pair<ll, int> max = {-1, -1};
			for (int i = 0; i < N; ++i) {
				if (ind[i] < ord[i].size()) 
					max = std::max(max, {ord[i][ind[i]].first - d[i], i});
			}
			while (ptr < que.size() && que[ptr].first > max.first) {
				int id = que[ptr++].second;
				// std::cerr << id << " " << d[V[id]] << "\n";
				ans[id] = std::min(ans[id], d[V[id]]);
				for (int i = 0; i < N; ++i) {
					if (d[i] < INF) 
						ans[id] = std::min(ans[id], S - T[id] + t[i][i][V[id]]);
				}
			}
			if (max.first < 0) break;
			int u = max.second;
			int v = ord[u][ind[u]++].second;
			for (int i = 0; i < N; ++i) {
				if (t[u][v][i] < S) 
					d[i] = std::min(d[i], t[u][v][i] - max.first);
			}
		}
	}
	return ans;
}

Compilation message

escape_route.cpp: In function 'std::vector<long long int> calculate_necessary_time(int, int, long long int, 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:84:16: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |     if (ind[i] < ord[i].size())
escape_route.cpp:87:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |    while (ptr < que.size() && que[ptr].first > max.first) {
      |           ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 26 ms 64992 KB Output is correct
2 Correct 33 ms 65044 KB Output is correct
3 Correct 60 ms 65072 KB Output is correct
4 Correct 26 ms 64936 KB Output is correct
5 Correct 38 ms 64980 KB Output is correct
6 Correct 25 ms 65056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1356 ms 137792 KB Output is correct
2 Correct 1351 ms 137204 KB Output is correct
3 Correct 1290 ms 137036 KB Output is correct
4 Correct 1347 ms 137112 KB Output is correct
5 Correct 1400 ms 137132 KB Output is correct
6 Correct 25 ms 64956 KB Output is correct
7 Correct 1321 ms 137088 KB Output is correct
8 Correct 1283 ms 136572 KB Output is correct
9 Correct 1336 ms 137096 KB Output is correct
10 Correct 1433 ms 137112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 64992 KB Output is correct
2 Correct 33 ms 65044 KB Output is correct
3 Correct 60 ms 65072 KB Output is correct
4 Correct 26 ms 64936 KB Output is correct
5 Correct 38 ms 64980 KB Output is correct
6 Correct 25 ms 65056 KB Output is correct
7 Correct 1356 ms 137792 KB Output is correct
8 Correct 1351 ms 137204 KB Output is correct
9 Correct 1290 ms 137036 KB Output is correct
10 Correct 1347 ms 137112 KB Output is correct
11 Correct 1400 ms 137132 KB Output is correct
12 Correct 25 ms 64956 KB Output is correct
13 Correct 1321 ms 137088 KB Output is correct
14 Correct 1283 ms 136572 KB Output is correct
15 Correct 1336 ms 137096 KB Output is correct
16 Correct 1433 ms 137112 KB Output is correct
17 Correct 1504 ms 157172 KB Output is correct
18 Correct 1541 ms 156964 KB Output is correct
19 Correct 1556 ms 175788 KB Output is correct
20 Correct 1484 ms 156324 KB Output is correct
21 Correct 1654 ms 182260 KB Output is correct
22 Correct 1771 ms 183200 KB Output is correct
23 Correct 1591 ms 155544 KB Output is correct
24 Correct 1535 ms 193112 KB Output is correct
25 Correct 1515 ms 155468 KB Output is correct
26 Correct 1574 ms 182216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 64992 KB Output is correct
2 Correct 33 ms 65044 KB Output is correct
3 Correct 60 ms 65072 KB Output is correct
4 Correct 26 ms 64936 KB Output is correct
5 Correct 38 ms 64980 KB Output is correct
6 Correct 25 ms 65056 KB Output is correct
7 Correct 1356 ms 137792 KB Output is correct
8 Correct 1351 ms 137204 KB Output is correct
9 Correct 1290 ms 137036 KB Output is correct
10 Correct 1347 ms 137112 KB Output is correct
11 Correct 1400 ms 137132 KB Output is correct
12 Correct 25 ms 64956 KB Output is correct
13 Correct 1321 ms 137088 KB Output is correct
14 Correct 1283 ms 136572 KB Output is correct
15 Correct 1336 ms 137096 KB Output is correct
16 Correct 1433 ms 137112 KB Output is correct
17 Correct 1504 ms 157172 KB Output is correct
18 Correct 1541 ms 156964 KB Output is correct
19 Correct 1556 ms 175788 KB Output is correct
20 Correct 1484 ms 156324 KB Output is correct
21 Correct 1654 ms 182260 KB Output is correct
22 Correct 1771 ms 183200 KB Output is correct
23 Correct 1591 ms 155544 KB Output is correct
24 Correct 1535 ms 193112 KB Output is correct
25 Correct 1515 ms 155468 KB Output is correct
26 Correct 1574 ms 182216 KB Output is correct
27 Correct 1936 ms 155788 KB Output is correct
28 Correct 1918 ms 156044 KB Output is correct
29 Correct 2070 ms 173916 KB Output is correct
30 Correct 2050 ms 155844 KB Output is correct
31 Correct 2000 ms 184016 KB Output is correct
32 Correct 1946 ms 183440 KB Output is correct
33 Correct 1787 ms 193556 KB Output is correct
34 Correct 2021 ms 155916 KB Output is correct
35 Correct 2094 ms 183784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 64992 KB Output is correct
2 Correct 33 ms 65044 KB Output is correct
3 Correct 60 ms 65072 KB Output is correct
4 Correct 26 ms 64936 KB Output is correct
5 Correct 38 ms 64980 KB Output is correct
6 Correct 25 ms 65056 KB Output is correct
7 Correct 1356 ms 137792 KB Output is correct
8 Correct 1351 ms 137204 KB Output is correct
9 Correct 1290 ms 137036 KB Output is correct
10 Correct 1347 ms 137112 KB Output is correct
11 Correct 1400 ms 137132 KB Output is correct
12 Correct 25 ms 64956 KB Output is correct
13 Correct 1321 ms 137088 KB Output is correct
14 Correct 1283 ms 136572 KB Output is correct
15 Correct 1336 ms 137096 KB Output is correct
16 Correct 1433 ms 137112 KB Output is correct
17 Correct 1504 ms 157172 KB Output is correct
18 Correct 1541 ms 156964 KB Output is correct
19 Correct 1556 ms 175788 KB Output is correct
20 Correct 1484 ms 156324 KB Output is correct
21 Correct 1654 ms 182260 KB Output is correct
22 Correct 1771 ms 183200 KB Output is correct
23 Correct 1591 ms 155544 KB Output is correct
24 Correct 1535 ms 193112 KB Output is correct
25 Correct 1515 ms 155468 KB Output is correct
26 Correct 1574 ms 182216 KB Output is correct
27 Correct 1936 ms 155788 KB Output is correct
28 Correct 1918 ms 156044 KB Output is correct
29 Correct 2070 ms 173916 KB Output is correct
30 Correct 2050 ms 155844 KB Output is correct
31 Correct 2000 ms 184016 KB Output is correct
32 Correct 1946 ms 183440 KB Output is correct
33 Correct 1787 ms 193556 KB Output is correct
34 Correct 2021 ms 155916 KB Output is correct
35 Correct 2094 ms 183784 KB Output is correct
36 Correct 2949 ms 158884 KB Output is correct
37 Correct 2959 ms 157724 KB Output is correct
38 Correct 2842 ms 162416 KB Output is correct
39 Correct 2913 ms 188904 KB Output is correct
40 Correct 2949 ms 189148 KB Output is correct
41 Correct 2040 ms 193780 KB Output is correct
42 Correct 2916 ms 157220 KB Output is correct
43 Correct 2869 ms 156936 KB Output is correct