# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
682614 | 2023-01-16T15:28:39 Z | TS_2392 | Toll (BOI17_toll) | C++14 | 193 ms | 136652 KB |
#include <bits/stdc++.h> #define fileIO(name) if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);} #define SPEED ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0) #define ctz(x) __builtin_ctz(x) #define rall(x) (x).rbegin(), (x).rend() #define all(x) (x).begin(), (x).end() #define sqr(x) (x) * (x) #define eb emplace_back #define epl emplace #define lwb lower_bound #define upb upper_bound #define mp make_pair #define fi first #define se second using namespace std; typedef long long ll; typedef long double ldb; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<int, ll> pil; typedef pair<int, int> pii; typedef pair<double, double> pdd; template<class T1, class T2> bool minimize(T1 &a, T2 b){ if(a > b){a = b; return true;} return false; } template<class T1, class T2> bool maximize(T1 &a, T2 b){ if(a < b){a = b; return true;} return false; } const int N = 5e4 + 3; const ll oo = 1e10; int k, m, n, qsn; ll d[N * 5][17][5]; int real_id(int i, int j){ return i * k + j; } int main(){ SPEED; fileIO(""); cin >> k >> n >> m >> qsn; for(int u = 0; u < 4 * n; ++u){ for(int i = 0; i < 17; ++i){ for(int j = 0; j < k; ++j) d[u][i][j] = oo; } } for(int i = 1; i <= m; ++i){ int u, v; cin >> u >> v >> d[u][0][v % k]; } for(int i = 1; i < 17; ++i) for(int u = 0; u < n; ++u){ for(int j = 0; j < k; ++j) for(int jj = 0; jj < k; ++jj){ minimize(d[u][i][j], d[u][i - 1][jj] + d[real_id(u / k + (1 << i - 1), jj)][i - 1][j]); } } while(qsn--){ int x, y, prefloor, lastfloor; cin >> x >> y; prefloor = x / k, lastfloor = y / k; if(prefloor < lastfloor){ int delta = lastfloor - prefloor, fstbit = ctz(delta), msk = 0; delta -= 1 << fstbit; prefloor += 1 << fstbit; ll dist[2][k]; for(int i = 0; i < k; ++i) dist[msk][i] = d[x][fstbit][i]; for(int curbit = 0; curbit < 17; ++curbit) if(delta >> curbit & 1){ msk ^= 1; for(int i = 0; i < k; ++i){ dist[msk][i] = oo; for(int ii = 0; ii < k; ++ii){ minimize(dist[msk][i], dist[msk ^ 1][ii] + d[real_id(prefloor, ii)][curbit][i]); } } prefloor += 1 << curbit; } cout << (dist[msk][y % k] < oo ? dist[msk][y % k] : -1) << '\n'; } else cout << -1 << '\n'; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 81 ms | 133436 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 2 ms | 2900 KB | Output is correct |
6 | Correct | 2 ms | 2900 KB | Output is correct |
7 | Correct | 3 ms | 2900 KB | Output is correct |
8 | Correct | 88 ms | 133416 KB | Output is correct |
9 | Correct | 88 ms | 133432 KB | Output is correct |
10 | Correct | 67 ms | 133404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 108 ms | 133392 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 5 ms | 3028 KB | Output is correct |
8 | Correct | 8 ms | 3084 KB | Output is correct |
9 | Correct | 78 ms | 134236 KB | Output is correct |
10 | Correct | 151 ms | 135636 KB | Output is correct |
11 | Correct | 116 ms | 135064 KB | Output is correct |
12 | Correct | 134 ms | 134668 KB | Output is correct |
13 | Correct | 130 ms | 82664 KB | Output is correct |
14 | Correct | 95 ms | 81600 KB | Output is correct |
15 | Correct | 111 ms | 81360 KB | Output is correct |
16 | Correct | 114 ms | 81356 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 2 ms | 2900 KB | Output is correct |
7 | Correct | 2 ms | 3028 KB | Output is correct |
8 | Correct | 4 ms | 3028 KB | Output is correct |
9 | Correct | 5 ms | 3044 KB | Output is correct |
10 | Correct | 89 ms | 134092 KB | Output is correct |
11 | Correct | 121 ms | 134872 KB | Output is correct |
12 | Correct | 136 ms | 135544 KB | Output is correct |
13 | Correct | 151 ms | 135800 KB | Output is correct |
14 | Correct | 161 ms | 135128 KB | Output is correct |
15 | Correct | 105 ms | 81312 KB | Output is correct |
16 | Correct | 105 ms | 81332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 2 ms | 2900 KB | Output is correct |
7 | Correct | 2 ms | 3028 KB | Output is correct |
8 | Correct | 4 ms | 3028 KB | Output is correct |
9 | Correct | 5 ms | 3044 KB | Output is correct |
10 | Correct | 89 ms | 134092 KB | Output is correct |
11 | Correct | 121 ms | 134872 KB | Output is correct |
12 | Correct | 136 ms | 135544 KB | Output is correct |
13 | Correct | 151 ms | 135800 KB | Output is correct |
14 | Correct | 161 ms | 135128 KB | Output is correct |
15 | Correct | 105 ms | 81312 KB | Output is correct |
16 | Correct | 105 ms | 81332 KB | Output is correct |
17 | Correct | 122 ms | 134900 KB | Output is correct |
18 | Correct | 1 ms | 340 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 1 ms | 340 KB | Output is correct |
21 | Correct | 1 ms | 328 KB | Output is correct |
22 | Correct | 1 ms | 340 KB | Output is correct |
23 | Correct | 3 ms | 3028 KB | Output is correct |
24 | Correct | 3 ms | 3032 KB | Output is correct |
25 | Correct | 5 ms | 3028 KB | Output is correct |
26 | Correct | 5 ms | 3028 KB | Output is correct |
27 | Correct | 77 ms | 134216 KB | Output is correct |
28 | Correct | 162 ms | 135588 KB | Output is correct |
29 | Correct | 146 ms | 135756 KB | Output is correct |
30 | Correct | 138 ms | 135172 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 81 ms | 133436 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 2 ms | 2900 KB | Output is correct |
6 | Correct | 2 ms | 2900 KB | Output is correct |
7 | Correct | 3 ms | 2900 KB | Output is correct |
8 | Correct | 88 ms | 133416 KB | Output is correct |
9 | Correct | 88 ms | 133432 KB | Output is correct |
10 | Correct | 67 ms | 133404 KB | Output is correct |
11 | Correct | 108 ms | 133392 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 332 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
17 | Correct | 5 ms | 3028 KB | Output is correct |
18 | Correct | 8 ms | 3084 KB | Output is correct |
19 | Correct | 78 ms | 134236 KB | Output is correct |
20 | Correct | 151 ms | 135636 KB | Output is correct |
21 | Correct | 116 ms | 135064 KB | Output is correct |
22 | Correct | 134 ms | 134668 KB | Output is correct |
23 | Correct | 130 ms | 82664 KB | Output is correct |
24 | Correct | 95 ms | 81600 KB | Output is correct |
25 | Correct | 111 ms | 81360 KB | Output is correct |
26 | Correct | 114 ms | 81356 KB | Output is correct |
27 | Correct | 0 ms | 340 KB | Output is correct |
28 | Correct | 1 ms | 340 KB | Output is correct |
29 | Correct | 0 ms | 332 KB | Output is correct |
30 | Correct | 1 ms | 340 KB | Output is correct |
31 | Correct | 1 ms | 340 KB | Output is correct |
32 | Correct | 2 ms | 2900 KB | Output is correct |
33 | Correct | 2 ms | 3028 KB | Output is correct |
34 | Correct | 4 ms | 3028 KB | Output is correct |
35 | Correct | 5 ms | 3044 KB | Output is correct |
36 | Correct | 89 ms | 134092 KB | Output is correct |
37 | Correct | 121 ms | 134872 KB | Output is correct |
38 | Correct | 136 ms | 135544 KB | Output is correct |
39 | Correct | 151 ms | 135800 KB | Output is correct |
40 | Correct | 161 ms | 135128 KB | Output is correct |
41 | Correct | 105 ms | 81312 KB | Output is correct |
42 | Correct | 105 ms | 81332 KB | Output is correct |
43 | Correct | 122 ms | 134900 KB | Output is correct |
44 | Correct | 1 ms | 340 KB | Output is correct |
45 | Correct | 1 ms | 340 KB | Output is correct |
46 | Correct | 1 ms | 340 KB | Output is correct |
47 | Correct | 1 ms | 328 KB | Output is correct |
48 | Correct | 1 ms | 340 KB | Output is correct |
49 | Correct | 3 ms | 3028 KB | Output is correct |
50 | Correct | 3 ms | 3032 KB | Output is correct |
51 | Correct | 5 ms | 3028 KB | Output is correct |
52 | Correct | 5 ms | 3028 KB | Output is correct |
53 | Correct | 77 ms | 134216 KB | Output is correct |
54 | Correct | 162 ms | 135588 KB | Output is correct |
55 | Correct | 146 ms | 135756 KB | Output is correct |
56 | Correct | 138 ms | 135172 KB | Output is correct |
57 | Correct | 193 ms | 136652 KB | Output is correct |
58 | Correct | 89 ms | 134304 KB | Output is correct |
59 | Correct | 127 ms | 135156 KB | Output is correct |