Submission #340414

# Submission time Handle Problem Language Result Execution time Memory
340414 2020-12-27T14:50:17 Z 8e7 Toll (BOI17_toll) C++14
100 / 100
255 ms 160348 KB
//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#define maxn 50005
#define int long long
using namespace std;
const int inf = (1<<30) - 1;
struct mat{
	int m[5][5];
	mat() {
		for (int i = 0;i < 5;i++) {
			for (int j = 0;j < 5;j++) m[i][j] = inf;
		}
	}
};
void print(mat a) {
	for (int i = 0;i < 5;i++) {
		for (int j = 0;j < 5;j++) cerr << a.m[i][j] << " ";
		cerr << endl;
	}
}
mat comb(mat a, mat b) {
	mat ret;
	for (int i = 0;i < 5;i++) {
		for (int j = 0;j < 5;j++) {
			ret.m[i][j] = inf;
			for (int k = 0;k < 5;k++) ret.m[i][j] = min(ret.m[i][j], a.m[i][k] + b.m[k][j]);
		}
	}
	return ret;
}
mat anc[16][maxn];


signed main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int k, n, m, o;
	cin >> k >> n >> m >> o;
	for (int i = 0;i < m;i++) {
		int a, b, t;
		cin >> a >> b >> t;
		anc[0][a / k].m[a % k][b % k] = t;
	}

	int len = (n + k - 1) / k;
	for (int i = 1;i < 16;i++) {
		for (int j = 0;j < len - (1<<i) + 1;j++) {
			anc[i][j] = comb(anc[i - 1][j], anc[i - 1][j + (1<<(i - 1))]);
		}
	}
	while (o--) {
		int a, b;
		cin >> a >> b;
		int ai = a / k, bi = b / k;
		mat cur;
		for (int i = 0;i < 5;i++) {
			cur.m[i][i] = 0;
		}
		for (int i = 15;i >= 0;i--) {
			if (ai + (1<<i) <= bi) {
				cur = comb(cur, anc[i][ai]);
				ai += 1<<i;
			}
		}
		int ans = cur.m[a % k][b % k];
		cout << (ans >= inf ? -1 : ans) << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 255 ms 157036 KB Output is correct
2 Correct 88 ms 156908 KB Output is correct
3 Correct 89 ms 156908 KB Output is correct
4 Correct 89 ms 156900 KB Output is correct
5 Correct 91 ms 156908 KB Output is correct
6 Correct 91 ms 156908 KB Output is correct
7 Correct 91 ms 156908 KB Output is correct
8 Correct 251 ms 157036 KB Output is correct
9 Correct 253 ms 156908 KB Output is correct
10 Correct 230 ms 156908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 196 ms 156908 KB Output is correct
2 Correct 89 ms 156908 KB Output is correct
3 Correct 88 ms 156908 KB Output is correct
4 Correct 90 ms 156872 KB Output is correct
5 Correct 89 ms 156908 KB Output is correct
6 Correct 89 ms 156908 KB Output is correct
7 Correct 101 ms 157036 KB Output is correct
8 Correct 102 ms 157036 KB Output is correct
9 Correct 246 ms 157804 KB Output is correct
10 Correct 186 ms 159212 KB Output is correct
11 Correct 202 ms 158828 KB Output is correct
12 Correct 165 ms 158188 KB Output is correct
13 Correct 149 ms 159468 KB Output is correct
14 Correct 146 ms 158444 KB Output is correct
15 Correct 126 ms 158188 KB Output is correct
16 Correct 125 ms 158188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 156908 KB Output is correct
2 Correct 91 ms 156872 KB Output is correct
3 Correct 91 ms 156908 KB Output is correct
4 Correct 88 ms 156908 KB Output is correct
5 Correct 89 ms 156908 KB Output is correct
6 Correct 90 ms 156908 KB Output is correct
7 Correct 90 ms 156908 KB Output is correct
8 Correct 89 ms 156908 KB Output is correct
9 Correct 90 ms 156908 KB Output is correct
10 Correct 229 ms 157676 KB Output is correct
11 Correct 177 ms 158444 KB Output is correct
12 Correct 169 ms 159212 KB Output is correct
13 Correct 173 ms 159388 KB Output is correct
14 Correct 162 ms 158700 KB Output is correct
15 Correct 121 ms 158060 KB Output is correct
16 Correct 125 ms 158060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 156908 KB Output is correct
2 Correct 91 ms 156872 KB Output is correct
3 Correct 91 ms 156908 KB Output is correct
4 Correct 88 ms 156908 KB Output is correct
5 Correct 89 ms 156908 KB Output is correct
6 Correct 90 ms 156908 KB Output is correct
7 Correct 90 ms 156908 KB Output is correct
8 Correct 89 ms 156908 KB Output is correct
9 Correct 90 ms 156908 KB Output is correct
10 Correct 229 ms 157676 KB Output is correct
11 Correct 177 ms 158444 KB Output is correct
12 Correct 169 ms 159212 KB Output is correct
13 Correct 173 ms 159388 KB Output is correct
14 Correct 162 ms 158700 KB Output is correct
15 Correct 121 ms 158060 KB Output is correct
16 Correct 125 ms 158060 KB Output is correct
17 Correct 186 ms 158572 KB Output is correct
18 Correct 88 ms 156940 KB Output is correct
19 Correct 89 ms 156928 KB Output is correct
20 Correct 93 ms 156908 KB Output is correct
21 Correct 91 ms 157036 KB Output is correct
22 Correct 89 ms 156908 KB Output is correct
23 Correct 94 ms 157036 KB Output is correct
24 Correct 93 ms 157036 KB Output is correct
25 Correct 93 ms 157036 KB Output is correct
26 Correct 93 ms 157036 KB Output is correct
27 Correct 230 ms 157824 KB Output is correct
28 Correct 174 ms 159212 KB Output is correct
29 Correct 186 ms 159596 KB Output is correct
30 Correct 168 ms 158828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 255 ms 157036 KB Output is correct
2 Correct 88 ms 156908 KB Output is correct
3 Correct 89 ms 156908 KB Output is correct
4 Correct 89 ms 156900 KB Output is correct
5 Correct 91 ms 156908 KB Output is correct
6 Correct 91 ms 156908 KB Output is correct
7 Correct 91 ms 156908 KB Output is correct
8 Correct 251 ms 157036 KB Output is correct
9 Correct 253 ms 156908 KB Output is correct
10 Correct 230 ms 156908 KB Output is correct
11 Correct 196 ms 156908 KB Output is correct
12 Correct 89 ms 156908 KB Output is correct
13 Correct 88 ms 156908 KB Output is correct
14 Correct 90 ms 156872 KB Output is correct
15 Correct 89 ms 156908 KB Output is correct
16 Correct 89 ms 156908 KB Output is correct
17 Correct 101 ms 157036 KB Output is correct
18 Correct 102 ms 157036 KB Output is correct
19 Correct 246 ms 157804 KB Output is correct
20 Correct 186 ms 159212 KB Output is correct
21 Correct 202 ms 158828 KB Output is correct
22 Correct 165 ms 158188 KB Output is correct
23 Correct 149 ms 159468 KB Output is correct
24 Correct 146 ms 158444 KB Output is correct
25 Correct 126 ms 158188 KB Output is correct
26 Correct 125 ms 158188 KB Output is correct
27 Correct 88 ms 156908 KB Output is correct
28 Correct 91 ms 156872 KB Output is correct
29 Correct 91 ms 156908 KB Output is correct
30 Correct 88 ms 156908 KB Output is correct
31 Correct 89 ms 156908 KB Output is correct
32 Correct 90 ms 156908 KB Output is correct
33 Correct 90 ms 156908 KB Output is correct
34 Correct 89 ms 156908 KB Output is correct
35 Correct 90 ms 156908 KB Output is correct
36 Correct 229 ms 157676 KB Output is correct
37 Correct 177 ms 158444 KB Output is correct
38 Correct 169 ms 159212 KB Output is correct
39 Correct 173 ms 159388 KB Output is correct
40 Correct 162 ms 158700 KB Output is correct
41 Correct 121 ms 158060 KB Output is correct
42 Correct 125 ms 158060 KB Output is correct
43 Correct 186 ms 158572 KB Output is correct
44 Correct 88 ms 156940 KB Output is correct
45 Correct 89 ms 156928 KB Output is correct
46 Correct 93 ms 156908 KB Output is correct
47 Correct 91 ms 157036 KB Output is correct
48 Correct 89 ms 156908 KB Output is correct
49 Correct 94 ms 157036 KB Output is correct
50 Correct 93 ms 157036 KB Output is correct
51 Correct 93 ms 157036 KB Output is correct
52 Correct 93 ms 157036 KB Output is correct
53 Correct 230 ms 157824 KB Output is correct
54 Correct 174 ms 159212 KB Output is correct
55 Correct 186 ms 159596 KB Output is correct
56 Correct 168 ms 158828 KB Output is correct
57 Correct 200 ms 160348 KB Output is correct
58 Correct 254 ms 157944 KB Output is correct
59 Correct 205 ms 158700 KB Output is correct