# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
836279 |
2023-08-24T09:42:21 Z |
nonono |
Toll (BOI17_toll) |
C++14 |
|
137 ms |
99144 KB |
#include <bits/stdc++.h>
using namespace std;
const int INF = 5e8;
const int LOG = 20;
const int mxN = 50005;
int K, N, M, O;
int up[mxN][5][5][LOG];
void minimize(int &a, int b) {
if(a > b) a = b;
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin >> K >> N >> M >> O;
for(int k = 0; k <= 18; k ++) {
for(int i = 0; i <= (N - 1) / K; i ++) {
for(int j1= 0; j1 < K; j1 ++) {
for(int j2 = 0; j2 < K; j2 ++) {
up[i][j1][j2][k] = INF;
}
}
}
}
for(int i = 1; i <= M; i ++) {
int a, b, t;
cin >> a >> b >> t;
if(a / K + 1 == b / K) {
minimize(up[a / K][a % K][b % K][0], t);
}
}
for(int k = 1; (1 << k) <= (N - 1) / K; k ++) {
for(int i = 0; i + (1 << k) <= (N - 1) / K; i ++) {
for(int j1 = 0; j1 < K; j1 ++) {
for(int j2 = 0; j2 < K; j2 ++) {
for(int j3 = 0; j3 < K; j3 ++) {
minimize(up[i][j1][j3][k], up[i][j1][j2][k - 1] + up[i + (1 << k - 1)][j2][j3][k - 1]);
}
}
}
}
}
while(O --) {
int a, b;
cin >> a >> b;
int typeA = a % K;
int typeB = b % K;
a /= K;
b /= K;
vector<int> ar(K);
for(int i = 0; i < K; i ++) ar[i] = INF;
ar[typeA] = 0;
int depth = b - a;
for(int k = 0; k <= 18; k ++) {
if(depth >> k & 1) {
vector<int> _ar(K);
for(int i = 0; i < K; i ++) {
_ar[i] = ar[i];
ar[i] = INF;
}
for(int i = 0; i < K; i ++) {
for(int j = 0; j < K; j ++) {
minimize(ar[i], _ar[j] + up[a][j][i][k]);
}
}
a += (1 << k);
}
}
if(ar[typeB] >= INF) cout << -1 << "\n"; else cout << ar[typeB] << "\n";
}
return 0;
}
Compilation message
toll.cpp: In function 'int main()':
toll.cpp:45:90: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
45 | minimize(up[i][j1][j3][k], up[i][j1][j2][k - 1] + up[i + (1 << k - 1)][j2][j3][k - 1]);
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
98796 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
2260 KB |
Output is correct |
6 |
Correct |
2 ms |
2260 KB |
Output is correct |
7 |
Correct |
2 ms |
2260 KB |
Output is correct |
8 |
Correct |
61 ms |
99028 KB |
Output is correct |
9 |
Correct |
60 ms |
99144 KB |
Output is correct |
10 |
Correct |
48 ms |
98252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
49856 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 |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
5 ms |
2388 KB |
Output is correct |
8 |
Correct |
5 ms |
1364 KB |
Output is correct |
9 |
Correct |
60 ms |
99020 KB |
Output is correct |
10 |
Correct |
111 ms |
35164 KB |
Output is correct |
11 |
Correct |
86 ms |
50892 KB |
Output is correct |
12 |
Correct |
90 ms |
34216 KB |
Output is correct |
13 |
Correct |
60 ms |
14468 KB |
Output is correct |
14 |
Correct |
54 ms |
21344 KB |
Output is correct |
15 |
Correct |
42 ms |
13264 KB |
Output is correct |
16 |
Correct |
53 ms |
13260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
2260 KB |
Output is correct |
7 |
Correct |
1 ms |
1236 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
3 ms |
852 KB |
Output is correct |
10 |
Correct |
51 ms |
98892 KB |
Output is correct |
11 |
Correct |
76 ms |
50760 KB |
Output is correct |
12 |
Correct |
98 ms |
35088 KB |
Output is correct |
13 |
Correct |
115 ms |
35348 KB |
Output is correct |
14 |
Correct |
93 ms |
34732 KB |
Output is correct |
15 |
Correct |
41 ms |
13140 KB |
Output is correct |
16 |
Correct |
41 ms |
13140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
2260 KB |
Output is correct |
7 |
Correct |
1 ms |
1236 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
3 ms |
852 KB |
Output is correct |
10 |
Correct |
51 ms |
98892 KB |
Output is correct |
11 |
Correct |
76 ms |
50760 KB |
Output is correct |
12 |
Correct |
98 ms |
35088 KB |
Output is correct |
13 |
Correct |
115 ms |
35348 KB |
Output is correct |
14 |
Correct |
93 ms |
34732 KB |
Output is correct |
15 |
Correct |
41 ms |
13140 KB |
Output is correct |
16 |
Correct |
41 ms |
13140 KB |
Output is correct |
17 |
Correct |
72 ms |
50780 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
2260 KB |
Output is correct |
24 |
Correct |
2 ms |
1364 KB |
Output is correct |
25 |
Correct |
3 ms |
724 KB |
Output is correct |
26 |
Correct |
3 ms |
852 KB |
Output is correct |
27 |
Correct |
62 ms |
98956 KB |
Output is correct |
28 |
Correct |
112 ms |
35148 KB |
Output is correct |
29 |
Correct |
106 ms |
35404 KB |
Output is correct |
30 |
Correct |
106 ms |
34768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
98796 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
2260 KB |
Output is correct |
6 |
Correct |
2 ms |
2260 KB |
Output is correct |
7 |
Correct |
2 ms |
2260 KB |
Output is correct |
8 |
Correct |
61 ms |
99028 KB |
Output is correct |
9 |
Correct |
60 ms |
99144 KB |
Output is correct |
10 |
Correct |
48 ms |
98252 KB |
Output is correct |
11 |
Correct |
82 ms |
49856 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 |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
5 ms |
2388 KB |
Output is correct |
18 |
Correct |
5 ms |
1364 KB |
Output is correct |
19 |
Correct |
60 ms |
99020 KB |
Output is correct |
20 |
Correct |
111 ms |
35164 KB |
Output is correct |
21 |
Correct |
86 ms |
50892 KB |
Output is correct |
22 |
Correct |
90 ms |
34216 KB |
Output is correct |
23 |
Correct |
60 ms |
14468 KB |
Output is correct |
24 |
Correct |
54 ms |
21344 KB |
Output is correct |
25 |
Correct |
42 ms |
13264 KB |
Output is correct |
26 |
Correct |
53 ms |
13260 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
2260 KB |
Output is correct |
33 |
Correct |
1 ms |
1236 KB |
Output is correct |
34 |
Correct |
2 ms |
724 KB |
Output is correct |
35 |
Correct |
3 ms |
852 KB |
Output is correct |
36 |
Correct |
51 ms |
98892 KB |
Output is correct |
37 |
Correct |
76 ms |
50760 KB |
Output is correct |
38 |
Correct |
98 ms |
35088 KB |
Output is correct |
39 |
Correct |
115 ms |
35348 KB |
Output is correct |
40 |
Correct |
93 ms |
34732 KB |
Output is correct |
41 |
Correct |
41 ms |
13140 KB |
Output is correct |
42 |
Correct |
41 ms |
13140 KB |
Output is correct |
43 |
Correct |
72 ms |
50780 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
0 ms |
332 KB |
Output is correct |
46 |
Correct |
0 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
340 KB |
Output is correct |
49 |
Correct |
3 ms |
2260 KB |
Output is correct |
50 |
Correct |
2 ms |
1364 KB |
Output is correct |
51 |
Correct |
3 ms |
724 KB |
Output is correct |
52 |
Correct |
3 ms |
852 KB |
Output is correct |
53 |
Correct |
62 ms |
98956 KB |
Output is correct |
54 |
Correct |
112 ms |
35148 KB |
Output is correct |
55 |
Correct |
106 ms |
35404 KB |
Output is correct |
56 |
Correct |
106 ms |
34768 KB |
Output is correct |
57 |
Correct |
137 ms |
28080 KB |
Output is correct |
58 |
Correct |
68 ms |
99032 KB |
Output is correct |
59 |
Correct |
86 ms |
50980 KB |
Output is correct |