# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
130424 | 2019-07-15T07:48:54 Z | win11905 | Toll (BOI17_toll) | C++11 | 426 ms | 49952 KB |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int k, n, m, o; int main() { scanf("%d %d %d %d", &k, &n, &m, &o); int h = n/k+1; vector<vector<vector<vector<int>>>> d(h, vector<vector<vector<int>>>(k, vector<vector<int>>(16, vector<int>(k, INF)))); for(int i = 0, a, b, c; i < m; ++i) { scanf("%d %d %d", &a, &b, &c); d[a/k][a%k][0][b%k] = c; } for(int z = 1; z < 16; ++z) for(int i = 0; i < h; ++i) for(int j = 0; j < k; ++j) for(int x = 0; x < k; ++x) for(int y = 0; y < k; ++y) if(i + (1<<(z-1)) < h) d[i][j][z][x] = min(d[i][j][z][x], d[i][j][z-1][y] + d[i+(1<<(z-1))][y][z-1][x]); for(int i = 0, a, b; i < o; ++i) { scanf("%d %d", &a, &b); if(a/k >= b/k) { puts("-1"); continue; } vector<int> ret = d[a/k][a%k][0]; int p = b % k; a = (a / k) + 1, b = b / k; for(int j = 15; ~j; --j) if(a + (1 << j) <= b) { vector<int> nret(k, INF); for(int x = 0; x < k; ++x) for(int y = 0; y < k; ++y) nret[y] = min(nret[y], ret[x] + d[a][x][j][y]); a += (1 << j); ret = nret; } printf("%d\n", ret[p] == INF ? -1 : ret[p]); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 211 ms | 48864 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 5 ms | 1272 KB | Output is correct |
6 | Correct | 5 ms | 1272 KB | Output is correct |
7 | Correct | 5 ms | 1272 KB | Output is correct |
8 | Correct | 206 ms | 48760 KB | Output is correct |
9 | Correct | 203 ms | 48632 KB | Output is correct |
10 | Correct | 159 ms | 47864 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 318 ms | 48888 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 252 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 11 ms | 1400 KB | Output is correct |
8 | Correct | 12 ms | 1400 KB | Output is correct |
9 | Correct | 181 ms | 48632 KB | Output is correct |
10 | Correct | 318 ms | 49016 KB | Output is correct |
11 | Correct | 275 ms | 48900 KB | Output is correct |
12 | Correct | 277 ms | 47992 KB | Output is correct |
13 | Correct | 275 ms | 30328 KB | Output is correct |
14 | Correct | 178 ms | 29560 KB | Output is correct |
15 | Correct | 235 ms | 29432 KB | Output is correct |
16 | Correct | 231 ms | 29176 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 2 ms | 380 KB | Output is correct |
6 | Correct | 4 ms | 1272 KB | Output is correct |
7 | Correct | 5 ms | 1272 KB | Output is correct |
8 | Correct | 8 ms | 1272 KB | Output is correct |
9 | Correct | 7 ms | 1272 KB | Output is correct |
10 | Correct | 203 ms | 48608 KB | Output is correct |
11 | Correct | 260 ms | 48760 KB | Output is correct |
12 | Correct | 309 ms | 48888 KB | Output is correct |
13 | Correct | 336 ms | 49104 KB | Output is correct |
14 | Correct | 286 ms | 48504 KB | Output is correct |
15 | Correct | 218 ms | 29308 KB | Output is correct |
16 | Correct | 220 ms | 29180 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 2 ms | 380 KB | Output is correct |
6 | Correct | 4 ms | 1272 KB | Output is correct |
7 | Correct | 5 ms | 1272 KB | Output is correct |
8 | Correct | 8 ms | 1272 KB | Output is correct |
9 | Correct | 7 ms | 1272 KB | Output is correct |
10 | Correct | 203 ms | 48608 KB | Output is correct |
11 | Correct | 260 ms | 48760 KB | Output is correct |
12 | Correct | 309 ms | 48888 KB | Output is correct |
13 | Correct | 336 ms | 49104 KB | Output is correct |
14 | Correct | 286 ms | 48504 KB | Output is correct |
15 | Correct | 218 ms | 29308 KB | Output is correct |
16 | Correct | 220 ms | 29180 KB | Output is correct |
17 | Correct | 267 ms | 48736 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
19 | Correct | 2 ms | 376 KB | Output is correct |
20 | Correct | 2 ms | 376 KB | Output is correct |
21 | Correct | 2 ms | 376 KB | Output is correct |
22 | Correct | 2 ms | 376 KB | Output is correct |
23 | Correct | 7 ms | 1272 KB | Output is correct |
24 | Correct | 7 ms | 1272 KB | Output is correct |
25 | Correct | 10 ms | 1272 KB | Output is correct |
26 | Correct | 9 ms | 1400 KB | Output is correct |
27 | Correct | 172 ms | 48504 KB | Output is correct |
28 | Correct | 321 ms | 48988 KB | Output is correct |
29 | Correct | 338 ms | 49244 KB | Output is correct |
30 | Correct | 302 ms | 48476 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 211 ms | 48864 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 5 ms | 1272 KB | Output is correct |
6 | Correct | 5 ms | 1272 KB | Output is correct |
7 | Correct | 5 ms | 1272 KB | Output is correct |
8 | Correct | 206 ms | 48760 KB | Output is correct |
9 | Correct | 203 ms | 48632 KB | Output is correct |
10 | Correct | 159 ms | 47864 KB | Output is correct |
11 | Correct | 318 ms | 48888 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 252 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 11 ms | 1400 KB | Output is correct |
18 | Correct | 12 ms | 1400 KB | Output is correct |
19 | Correct | 181 ms | 48632 KB | Output is correct |
20 | Correct | 318 ms | 49016 KB | Output is correct |
21 | Correct | 275 ms | 48900 KB | Output is correct |
22 | Correct | 277 ms | 47992 KB | Output is correct |
23 | Correct | 275 ms | 30328 KB | Output is correct |
24 | Correct | 178 ms | 29560 KB | Output is correct |
25 | Correct | 235 ms | 29432 KB | Output is correct |
26 | Correct | 231 ms | 29176 KB | Output is correct |
27 | Correct | 2 ms | 376 KB | Output is correct |
28 | Correct | 2 ms | 376 KB | Output is correct |
29 | Correct | 2 ms | 376 KB | Output is correct |
30 | Correct | 2 ms | 256 KB | Output is correct |
31 | Correct | 2 ms | 380 KB | Output is correct |
32 | Correct | 4 ms | 1272 KB | Output is correct |
33 | Correct | 5 ms | 1272 KB | Output is correct |
34 | Correct | 8 ms | 1272 KB | Output is correct |
35 | Correct | 7 ms | 1272 KB | Output is correct |
36 | Correct | 203 ms | 48608 KB | Output is correct |
37 | Correct | 260 ms | 48760 KB | Output is correct |
38 | Correct | 309 ms | 48888 KB | Output is correct |
39 | Correct | 336 ms | 49104 KB | Output is correct |
40 | Correct | 286 ms | 48504 KB | Output is correct |
41 | Correct | 218 ms | 29308 KB | Output is correct |
42 | Correct | 220 ms | 29180 KB | Output is correct |
43 | Correct | 267 ms | 48736 KB | Output is correct |
44 | Correct | 2 ms | 376 KB | Output is correct |
45 | Correct | 2 ms | 376 KB | Output is correct |
46 | Correct | 2 ms | 376 KB | Output is correct |
47 | Correct | 2 ms | 376 KB | Output is correct |
48 | Correct | 2 ms | 376 KB | Output is correct |
49 | Correct | 7 ms | 1272 KB | Output is correct |
50 | Correct | 7 ms | 1272 KB | Output is correct |
51 | Correct | 10 ms | 1272 KB | Output is correct |
52 | Correct | 9 ms | 1400 KB | Output is correct |
53 | Correct | 172 ms | 48504 KB | Output is correct |
54 | Correct | 321 ms | 48988 KB | Output is correct |
55 | Correct | 338 ms | 49244 KB | Output is correct |
56 | Correct | 302 ms | 48476 KB | Output is correct |
57 | Correct | 426 ms | 49952 KB | Output is correct |
58 | Correct | 206 ms | 48632 KB | Output is correct |
59 | Correct | 296 ms | 48888 KB | Output is correct |