# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
158123 | 2019-10-15T03:19:26 Z | PeppaPig | Toll (BOI17_toll) | C++14 | 254 ms | 81980 KB |
#include <bits/stdc++.h> using namespace std; int k, n, m, q; int bl[50005][5][5][16]; int main() { fill_n(bl[0][0][0], 50005 * 5 * 5 * 16, 1e9); scanf("%d %d %d %d", &k, &n, &m, &q); for(int i = 1, a, b, c; i <= m; i++) { scanf("%d %d %d", &a, &b, &c); bl[a / k][a % k][b % k][0] = c; } for(int i = 1; i <= 15; i++) for(int a = 0; a <= n / k + 1; a++) for(int b = 0; b < k; b++) for(int c = 0; c < k; c++) for(int t = 0; t < k; t++) if(a + (1 << (i - 1)) <= n / k + 1) bl[a][b][c][i] = min(bl[a][b][c][i], bl[a][b][t][i-1] + bl[a + (1 << (i - 1))][t][c][i-1]); while(q--) { int a, b; scanf("%d %d", &a, &b); if(a / k >= b / k) { printf("-1\n"); continue; } int ans = b % k, dp[5]; for(int i = 0; i < k; i++) dp[i] = bl[a / k][a % k][i][0]; a = (a / k) + 1, b = b / k; for(int i = 15; ~i; i--) if(a + (1 << i) <= b) { int ndp[5]; fill_n(ndp, 5, 1e9); for(int x = 0; x < k; x++) for(int y = 0; y < k; y++) ndp[x] = min(ndp[x], dp[y] + bl[a][y][x][i]); for(int j = 0; j < k; j++) dp[j] = ndp[j]; a += (1 << i); } if(dp[ans] == 1e9) printf("-1\n"); else printf("%d\n", dp[ans]); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 115 ms | 78712 KB | Output is correct |
2 | Correct | 70 ms | 78584 KB | Output is correct |
3 | Correct | 70 ms | 78636 KB | Output is correct |
4 | Correct | 69 ms | 78588 KB | Output is correct |
5 | Correct | 71 ms | 78580 KB | Output is correct |
6 | Correct | 71 ms | 78684 KB | Output is correct |
7 | Correct | 71 ms | 78584 KB | Output is correct |
8 | Correct | 117 ms | 79560 KB | Output is correct |
9 | Correct | 118 ms | 79640 KB | Output is correct |
10 | Correct | 90 ms | 78712 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 149 ms | 78748 KB | Output is correct |
2 | Correct | 69 ms | 78584 KB | Output is correct |
3 | Correct | 70 ms | 78648 KB | Output is correct |
4 | Correct | 70 ms | 78692 KB | Output is correct |
5 | Correct | 70 ms | 78556 KB | Output is correct |
6 | Correct | 70 ms | 78556 KB | Output is correct |
7 | Correct | 75 ms | 78712 KB | Output is correct |
8 | Correct | 76 ms | 78792 KB | Output is correct |
9 | Correct | 115 ms | 79608 KB | Output is correct |
10 | Correct | 186 ms | 80956 KB | Output is correct |
11 | Correct | 146 ms | 80476 KB | Output is correct |
12 | Correct | 146 ms | 79992 KB | Output is correct |
13 | Correct | 177 ms | 81168 KB | Output is correct |
14 | Correct | 133 ms | 80120 KB | Output is correct |
15 | Correct | 132 ms | 79864 KB | Output is correct |
16 | Correct | 133 ms | 79864 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 69 ms | 78712 KB | Output is correct |
2 | Correct | 70 ms | 78584 KB | Output is correct |
3 | Correct | 70 ms | 78648 KB | Output is correct |
4 | Correct | 69 ms | 78584 KB | Output is correct |
5 | Correct | 70 ms | 78588 KB | Output is correct |
6 | Correct | 79 ms | 78540 KB | Output is correct |
7 | Correct | 80 ms | 78584 KB | Output is correct |
8 | Correct | 72 ms | 78556 KB | Output is correct |
9 | Correct | 72 ms | 78584 KB | Output is correct |
10 | Correct | 110 ms | 78584 KB | Output is correct |
11 | Correct | 138 ms | 80120 KB | Output is correct |
12 | Correct | 178 ms | 80816 KB | Output is correct |
13 | Correct | 180 ms | 81056 KB | Output is correct |
14 | Correct | 195 ms | 80416 KB | Output is correct |
15 | Correct | 146 ms | 79708 KB | Output is correct |
16 | Correct | 139 ms | 79864 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 69 ms | 78712 KB | Output is correct |
2 | Correct | 70 ms | 78584 KB | Output is correct |
3 | Correct | 70 ms | 78648 KB | Output is correct |
4 | Correct | 69 ms | 78584 KB | Output is correct |
5 | Correct | 70 ms | 78588 KB | Output is correct |
6 | Correct | 79 ms | 78540 KB | Output is correct |
7 | Correct | 80 ms | 78584 KB | Output is correct |
8 | Correct | 72 ms | 78556 KB | Output is correct |
9 | Correct | 72 ms | 78584 KB | Output is correct |
10 | Correct | 110 ms | 78584 KB | Output is correct |
11 | Correct | 138 ms | 80120 KB | Output is correct |
12 | Correct | 178 ms | 80816 KB | Output is correct |
13 | Correct | 180 ms | 81056 KB | Output is correct |
14 | Correct | 195 ms | 80416 KB | Output is correct |
15 | Correct | 146 ms | 79708 KB | Output is correct |
16 | Correct | 139 ms | 79864 KB | Output is correct |
17 | Correct | 165 ms | 80284 KB | Output is correct |
18 | Correct | 72 ms | 78640 KB | Output is correct |
19 | Correct | 79 ms | 78584 KB | Output is correct |
20 | Correct | 81 ms | 78596 KB | Output is correct |
21 | Correct | 81 ms | 78760 KB | Output is correct |
22 | Correct | 70 ms | 78584 KB | Output is correct |
23 | Correct | 72 ms | 78712 KB | Output is correct |
24 | Correct | 73 ms | 78712 KB | Output is correct |
25 | Correct | 74 ms | 78712 KB | Output is correct |
26 | Correct | 73 ms | 78712 KB | Output is correct |
27 | Correct | 118 ms | 79480 KB | Output is correct |
28 | Correct | 178 ms | 80760 KB | Output is correct |
29 | Correct | 187 ms | 81116 KB | Output is correct |
30 | Correct | 193 ms | 80504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 115 ms | 78712 KB | Output is correct |
2 | Correct | 70 ms | 78584 KB | Output is correct |
3 | Correct | 70 ms | 78636 KB | Output is correct |
4 | Correct | 69 ms | 78588 KB | Output is correct |
5 | Correct | 71 ms | 78580 KB | Output is correct |
6 | Correct | 71 ms | 78684 KB | Output is correct |
7 | Correct | 71 ms | 78584 KB | Output is correct |
8 | Correct | 117 ms | 79560 KB | Output is correct |
9 | Correct | 118 ms | 79640 KB | Output is correct |
10 | Correct | 90 ms | 78712 KB | Output is correct |
11 | Correct | 149 ms | 78748 KB | Output is correct |
12 | Correct | 69 ms | 78584 KB | Output is correct |
13 | Correct | 70 ms | 78648 KB | Output is correct |
14 | Correct | 70 ms | 78692 KB | Output is correct |
15 | Correct | 70 ms | 78556 KB | Output is correct |
16 | Correct | 70 ms | 78556 KB | Output is correct |
17 | Correct | 75 ms | 78712 KB | Output is correct |
18 | Correct | 76 ms | 78792 KB | Output is correct |
19 | Correct | 115 ms | 79608 KB | Output is correct |
20 | Correct | 186 ms | 80956 KB | Output is correct |
21 | Correct | 146 ms | 80476 KB | Output is correct |
22 | Correct | 146 ms | 79992 KB | Output is correct |
23 | Correct | 177 ms | 81168 KB | Output is correct |
24 | Correct | 133 ms | 80120 KB | Output is correct |
25 | Correct | 132 ms | 79864 KB | Output is correct |
26 | Correct | 133 ms | 79864 KB | Output is correct |
27 | Correct | 69 ms | 78712 KB | Output is correct |
28 | Correct | 70 ms | 78584 KB | Output is correct |
29 | Correct | 70 ms | 78648 KB | Output is correct |
30 | Correct | 69 ms | 78584 KB | Output is correct |
31 | Correct | 70 ms | 78588 KB | Output is correct |
32 | Correct | 79 ms | 78540 KB | Output is correct |
33 | Correct | 80 ms | 78584 KB | Output is correct |
34 | Correct | 72 ms | 78556 KB | Output is correct |
35 | Correct | 72 ms | 78584 KB | Output is correct |
36 | Correct | 110 ms | 78584 KB | Output is correct |
37 | Correct | 138 ms | 80120 KB | Output is correct |
38 | Correct | 178 ms | 80816 KB | Output is correct |
39 | Correct | 180 ms | 81056 KB | Output is correct |
40 | Correct | 195 ms | 80416 KB | Output is correct |
41 | Correct | 146 ms | 79708 KB | Output is correct |
42 | Correct | 139 ms | 79864 KB | Output is correct |
43 | Correct | 165 ms | 80284 KB | Output is correct |
44 | Correct | 72 ms | 78640 KB | Output is correct |
45 | Correct | 79 ms | 78584 KB | Output is correct |
46 | Correct | 81 ms | 78596 KB | Output is correct |
47 | Correct | 81 ms | 78760 KB | Output is correct |
48 | Correct | 70 ms | 78584 KB | Output is correct |
49 | Correct | 72 ms | 78712 KB | Output is correct |
50 | Correct | 73 ms | 78712 KB | Output is correct |
51 | Correct | 74 ms | 78712 KB | Output is correct |
52 | Correct | 73 ms | 78712 KB | Output is correct |
53 | Correct | 118 ms | 79480 KB | Output is correct |
54 | Correct | 178 ms | 80760 KB | Output is correct |
55 | Correct | 187 ms | 81116 KB | Output is correct |
56 | Correct | 193 ms | 80504 KB | Output is correct |
57 | Correct | 254 ms | 81980 KB | Output is correct |
58 | Correct | 117 ms | 79592 KB | Output is correct |
59 | Correct | 154 ms | 80484 KB | Output is correct |