# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
444550 | 2021-07-14T08:37:34 Z | BeanZ | Toll (BOI17_toll) | C++14 | 317 ms | 189508 KB |
// I_Love_LPL 1y0m6d #include <bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' const int N = 5e4 + 5; long long mod = 1e9 + 7; const int lim = 4e5 + 5; const int lg = 18; const int base = 37; const long double eps = 1e-6; ll dp[N][lg + 1][5][5], temp[5], res[5]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("tests.inp", "r")){ freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } ll k, n, m, q; cin >> k >> n >> m >> q; for (int i = 0; i < n; i++){ for (int j = 0; j <= lg; j++){ for (int g = 0; g < k; g++){ for (int t = 0; t < k; t++){ dp[i][j][g][t] = 1e9; } } } } for (int i = 1; i <= m; i++){ ll u, v, c; cin >> u >> v >> c; dp[u][0][u % k][v % k] = c; } for (int lo = 1; lo <= lg; lo++){ for (int i = 0; i < n; i++){ for (int j = 0; j < k; j++){ // des for (int g = 0; g < k; g++){ // trans ll id = i + k * (1 << (lo - 1)) - (i % k) + (g % k); if (id >= N) continue; dp[i][lo][i % k][j] = min(dp[i][lo][i % k][j], dp[i][lo - 1][i % k][g] + dp[i + k * (1 << (lo - 1)) - (i % k) + (g % k)][lo - 1][g % k][j]); } } } } while (q--){ ll u, v; cin >> u >> v; ll dep = (v / k) - (u / k); for (int i = 0; i < k; i++) res[i] = 1e9; res[u % k] = 0; ll cur = u / k; for (int i = 0; i <= lg; i++){ for (int g = 0; g < k; g++) temp[g] = 1e9; if (dep & (1 << i)){ for (int g = 0; g < k; g++){ // des for (int j = 0; j < k; j++){ // trans temp[g] = min(temp[g], res[j] + dp[cur * k + j][i][j][g]); } } cur = cur + (1 << i); for (int g = 0; g < k; g++) res[g] = temp[g]; } } if (res[v % k] < 1e9) cout << res[v % k] << endl; else cout << -1 << endl; } } /* Ans: Out: */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 135 ms | 186308 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 6 ms | 4044 KB | Output is correct |
6 | Correct | 6 ms | 4044 KB | Output is correct |
7 | Correct | 6 ms | 4044 KB | Output is correct |
8 | Correct | 138 ms | 186180 KB | Output is correct |
9 | Correct | 136 ms | 186336 KB | Output is correct |
10 | Correct | 114 ms | 186180 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 219 ms | 186272 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 15 ms | 4044 KB | Output is correct |
8 | Correct | 11 ms | 4148 KB | Output is correct |
9 | Correct | 132 ms | 186180 KB | Output is correct |
10 | Correct | 259 ms | 186212 KB | Output is correct |
11 | Correct | 223 ms | 187916 KB | Output is correct |
12 | Correct | 237 ms | 187460 KB | Output is correct |
13 | Correct | 265 ms | 114384 KB | Output is correct |
14 | Correct | 175 ms | 113424 KB | Output is correct |
15 | Correct | 210 ms | 113196 KB | Output is correct |
16 | Correct | 206 ms | 113144 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 6 ms | 4084 KB | Output is correct |
7 | Correct | 6 ms | 4044 KB | Output is correct |
8 | Correct | 11 ms | 4100 KB | Output is correct |
9 | Correct | 13 ms | 4044 KB | Output is correct |
10 | Correct | 143 ms | 186220 KB | Output is correct |
11 | Correct | 208 ms | 186292 KB | Output is correct |
12 | Correct | 254 ms | 186168 KB | Output is correct |
13 | Correct | 271 ms | 188624 KB | Output is correct |
14 | Correct | 246 ms | 188020 KB | Output is correct |
15 | Correct | 201 ms | 113284 KB | Output is correct |
16 | Correct | 207 ms | 113092 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 6 ms | 4084 KB | Output is correct |
7 | Correct | 6 ms | 4044 KB | Output is correct |
8 | Correct | 11 ms | 4100 KB | Output is correct |
9 | Correct | 13 ms | 4044 KB | Output is correct |
10 | Correct | 143 ms | 186220 KB | Output is correct |
11 | Correct | 208 ms | 186292 KB | Output is correct |
12 | Correct | 254 ms | 186168 KB | Output is correct |
13 | Correct | 271 ms | 188624 KB | Output is correct |
14 | Correct | 246 ms | 188020 KB | Output is correct |
15 | Correct | 201 ms | 113284 KB | Output is correct |
16 | Correct | 207 ms | 113092 KB | Output is correct |
17 | Correct | 229 ms | 187776 KB | Output is correct |
18 | Correct | 1 ms | 324 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 1 ms | 332 KB | Output is correct |
21 | Correct | 1 ms | 332 KB | Output is correct |
22 | Correct | 1 ms | 332 KB | Output is correct |
23 | Correct | 8 ms | 4052 KB | Output is correct |
24 | Correct | 8 ms | 4172 KB | Output is correct |
25 | Correct | 11 ms | 4176 KB | Output is correct |
26 | Correct | 10 ms | 4188 KB | Output is correct |
27 | Correct | 133 ms | 187076 KB | Output is correct |
28 | Correct | 257 ms | 188360 KB | Output is correct |
29 | Correct | 273 ms | 188696 KB | Output is correct |
30 | Correct | 254 ms | 188060 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 135 ms | 186308 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 6 ms | 4044 KB | Output is correct |
6 | Correct | 6 ms | 4044 KB | Output is correct |
7 | Correct | 6 ms | 4044 KB | Output is correct |
8 | Correct | 138 ms | 186180 KB | Output is correct |
9 | Correct | 136 ms | 186336 KB | Output is correct |
10 | Correct | 114 ms | 186180 KB | Output is correct |
11 | Correct | 219 ms | 186272 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 332 KB | Output is correct |
14 | Correct | 1 ms | 332 KB | Output is correct |
15 | Correct | 1 ms | 332 KB | Output is correct |
16 | Correct | 1 ms | 332 KB | Output is correct |
17 | Correct | 15 ms | 4044 KB | Output is correct |
18 | Correct | 11 ms | 4148 KB | Output is correct |
19 | Correct | 132 ms | 186180 KB | Output is correct |
20 | Correct | 259 ms | 186212 KB | Output is correct |
21 | Correct | 223 ms | 187916 KB | Output is correct |
22 | Correct | 237 ms | 187460 KB | Output is correct |
23 | Correct | 265 ms | 114384 KB | Output is correct |
24 | Correct | 175 ms | 113424 KB | Output is correct |
25 | Correct | 210 ms | 113196 KB | Output is correct |
26 | Correct | 206 ms | 113144 KB | Output is correct |
27 | Correct | 0 ms | 332 KB | Output is correct |
28 | Correct | 1 ms | 332 KB | Output is correct |
29 | Correct | 1 ms | 332 KB | Output is correct |
30 | Correct | 1 ms | 332 KB | Output is correct |
31 | Correct | 1 ms | 332 KB | Output is correct |
32 | Correct | 6 ms | 4084 KB | Output is correct |
33 | Correct | 6 ms | 4044 KB | Output is correct |
34 | Correct | 11 ms | 4100 KB | Output is correct |
35 | Correct | 13 ms | 4044 KB | Output is correct |
36 | Correct | 143 ms | 186220 KB | Output is correct |
37 | Correct | 208 ms | 186292 KB | Output is correct |
38 | Correct | 254 ms | 186168 KB | Output is correct |
39 | Correct | 271 ms | 188624 KB | Output is correct |
40 | Correct | 246 ms | 188020 KB | Output is correct |
41 | Correct | 201 ms | 113284 KB | Output is correct |
42 | Correct | 207 ms | 113092 KB | Output is correct |
43 | Correct | 229 ms | 187776 KB | Output is correct |
44 | Correct | 1 ms | 324 KB | Output is correct |
45 | Correct | 1 ms | 332 KB | Output is correct |
46 | Correct | 1 ms | 332 KB | Output is correct |
47 | Correct | 1 ms | 332 KB | Output is correct |
48 | Correct | 1 ms | 332 KB | Output is correct |
49 | Correct | 8 ms | 4052 KB | Output is correct |
50 | Correct | 8 ms | 4172 KB | Output is correct |
51 | Correct | 11 ms | 4176 KB | Output is correct |
52 | Correct | 10 ms | 4188 KB | Output is correct |
53 | Correct | 133 ms | 187076 KB | Output is correct |
54 | Correct | 257 ms | 188360 KB | Output is correct |
55 | Correct | 273 ms | 188696 KB | Output is correct |
56 | Correct | 254 ms | 188060 KB | Output is correct |
57 | Correct | 317 ms | 189508 KB | Output is correct |
58 | Correct | 141 ms | 187076 KB | Output is correct |
59 | Correct | 230 ms | 187944 KB | Output is correct |