# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
392209 |
2021-04-20T16:02:38 Z |
JerryLiu06 |
Toll (BOI17_toll) |
C++11 |
|
323 ms |
101476 KB |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
#define pb push_back
#define f first
#define s second
int K, N, M, O; int DP[50010][20][5][5], CUR[5][5];
void comb(int res[5][5], int A[5][5], int B[5][5]) {
for (int i = 0; i < 5; i++) for (int j = 0; j < 5; j++) {
for (int k = 0; k < 5; k++) res[i][j] = min(res[i][j], A[i][k] + B[k][j]);
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> K >> N >> M >> O; memset(DP, 0x3f, sizeof DP);
for (int i = 0; i < M; i++) {
int A, B, T; cin >> A >> B >> T; DP[A / K][0][A % K][B % K] = T;
}
for (int j = 1; j < 20; j++) for (int i = 0; i + (1 << (j - 1)) <= N / K; i++) {
comb(DP[i][j], DP[i][j - 1], DP[i + (1 << (j - 1))][j - 1]);
}
for (int i = 0; i < O; i++) {
int A, B; cin >> A >> B; memset(CUR, 0x3f, sizeof CUR);
for (int j = 0; j < K; j++) CUR[j][j] = 0;
int LEN = B / K - A / K; int ST = A / K;
for (int i = 20; i >= 0; i--) if (LEN & (1 << i)) {
int TMP[5][5]; memset(TMP, 0x3f, sizeof TMP);
comb(TMP, CUR, DP[ST][i]); memcpy(CUR, TMP, sizeof CUR); ST += (1 << i);
}
cout << (CUR[A % K][B % K] == 0x3f3f3f3f ? -1 : CUR[A % K][B % K]) << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
305 ms |
99268 KB |
Output is correct |
2 |
Correct |
50 ms |
98052 KB |
Output is correct |
3 |
Correct |
50 ms |
98116 KB |
Output is correct |
4 |
Correct |
49 ms |
98112 KB |
Output is correct |
5 |
Correct |
53 ms |
98100 KB |
Output is correct |
6 |
Correct |
54 ms |
98128 KB |
Output is correct |
7 |
Correct |
53 ms |
98180 KB |
Output is correct |
8 |
Correct |
323 ms |
99012 KB |
Output is correct |
9 |
Correct |
300 ms |
99012 KB |
Output is correct |
10 |
Correct |
280 ms |
98256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
201 ms |
99800 KB |
Output is correct |
2 |
Correct |
50 ms |
98192 KB |
Output is correct |
3 |
Correct |
49 ms |
98056 KB |
Output is correct |
4 |
Correct |
50 ms |
98116 KB |
Output is correct |
5 |
Correct |
51 ms |
98156 KB |
Output is correct |
6 |
Correct |
54 ms |
98116 KB |
Output is correct |
7 |
Correct |
63 ms |
98200 KB |
Output is correct |
8 |
Correct |
68 ms |
98376 KB |
Output is correct |
9 |
Correct |
292 ms |
99012 KB |
Output is correct |
10 |
Correct |
182 ms |
100420 KB |
Output is correct |
11 |
Correct |
200 ms |
99980 KB |
Output is correct |
12 |
Correct |
156 ms |
99428 KB |
Output is correct |
13 |
Correct |
116 ms |
100548 KB |
Output is correct |
14 |
Correct |
114 ms |
99608 KB |
Output is correct |
15 |
Correct |
92 ms |
99476 KB |
Output is correct |
16 |
Correct |
91 ms |
99396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
98080 KB |
Output is correct |
2 |
Correct |
57 ms |
98140 KB |
Output is correct |
3 |
Correct |
50 ms |
98116 KB |
Output is correct |
4 |
Correct |
50 ms |
98124 KB |
Output is correct |
5 |
Correct |
50 ms |
98080 KB |
Output is correct |
6 |
Correct |
51 ms |
98120 KB |
Output is correct |
7 |
Correct |
50 ms |
98116 KB |
Output is correct |
8 |
Correct |
51 ms |
98152 KB |
Output is correct |
9 |
Correct |
51 ms |
98172 KB |
Output is correct |
10 |
Correct |
279 ms |
99020 KB |
Output is correct |
11 |
Correct |
185 ms |
99748 KB |
Output is correct |
12 |
Correct |
150 ms |
100224 KB |
Output is correct |
13 |
Correct |
167 ms |
100576 KB |
Output is correct |
14 |
Correct |
153 ms |
100028 KB |
Output is correct |
15 |
Correct |
87 ms |
99320 KB |
Output is correct |
16 |
Correct |
86 ms |
99228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
98080 KB |
Output is correct |
2 |
Correct |
57 ms |
98140 KB |
Output is correct |
3 |
Correct |
50 ms |
98116 KB |
Output is correct |
4 |
Correct |
50 ms |
98124 KB |
Output is correct |
5 |
Correct |
50 ms |
98080 KB |
Output is correct |
6 |
Correct |
51 ms |
98120 KB |
Output is correct |
7 |
Correct |
50 ms |
98116 KB |
Output is correct |
8 |
Correct |
51 ms |
98152 KB |
Output is correct |
9 |
Correct |
51 ms |
98172 KB |
Output is correct |
10 |
Correct |
279 ms |
99020 KB |
Output is correct |
11 |
Correct |
185 ms |
99748 KB |
Output is correct |
12 |
Correct |
150 ms |
100224 KB |
Output is correct |
13 |
Correct |
167 ms |
100576 KB |
Output is correct |
14 |
Correct |
153 ms |
100028 KB |
Output is correct |
15 |
Correct |
87 ms |
99320 KB |
Output is correct |
16 |
Correct |
86 ms |
99228 KB |
Output is correct |
17 |
Correct |
189 ms |
99804 KB |
Output is correct |
18 |
Correct |
50 ms |
98112 KB |
Output is correct |
19 |
Correct |
50 ms |
98128 KB |
Output is correct |
20 |
Correct |
50 ms |
98088 KB |
Output is correct |
21 |
Correct |
50 ms |
98116 KB |
Output is correct |
22 |
Correct |
50 ms |
98048 KB |
Output is correct |
23 |
Correct |
56 ms |
98120 KB |
Output is correct |
24 |
Correct |
55 ms |
98228 KB |
Output is correct |
25 |
Correct |
63 ms |
98196 KB |
Output is correct |
26 |
Correct |
55 ms |
98280 KB |
Output is correct |
27 |
Correct |
287 ms |
99004 KB |
Output is correct |
28 |
Correct |
166 ms |
100404 KB |
Output is correct |
29 |
Correct |
172 ms |
100548 KB |
Output is correct |
30 |
Correct |
171 ms |
100008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
305 ms |
99268 KB |
Output is correct |
2 |
Correct |
50 ms |
98052 KB |
Output is correct |
3 |
Correct |
50 ms |
98116 KB |
Output is correct |
4 |
Correct |
49 ms |
98112 KB |
Output is correct |
5 |
Correct |
53 ms |
98100 KB |
Output is correct |
6 |
Correct |
54 ms |
98128 KB |
Output is correct |
7 |
Correct |
53 ms |
98180 KB |
Output is correct |
8 |
Correct |
323 ms |
99012 KB |
Output is correct |
9 |
Correct |
300 ms |
99012 KB |
Output is correct |
10 |
Correct |
280 ms |
98256 KB |
Output is correct |
11 |
Correct |
201 ms |
99800 KB |
Output is correct |
12 |
Correct |
50 ms |
98192 KB |
Output is correct |
13 |
Correct |
49 ms |
98056 KB |
Output is correct |
14 |
Correct |
50 ms |
98116 KB |
Output is correct |
15 |
Correct |
51 ms |
98156 KB |
Output is correct |
16 |
Correct |
54 ms |
98116 KB |
Output is correct |
17 |
Correct |
63 ms |
98200 KB |
Output is correct |
18 |
Correct |
68 ms |
98376 KB |
Output is correct |
19 |
Correct |
292 ms |
99012 KB |
Output is correct |
20 |
Correct |
182 ms |
100420 KB |
Output is correct |
21 |
Correct |
200 ms |
99980 KB |
Output is correct |
22 |
Correct |
156 ms |
99428 KB |
Output is correct |
23 |
Correct |
116 ms |
100548 KB |
Output is correct |
24 |
Correct |
114 ms |
99608 KB |
Output is correct |
25 |
Correct |
92 ms |
99476 KB |
Output is correct |
26 |
Correct |
91 ms |
99396 KB |
Output is correct |
27 |
Correct |
51 ms |
98080 KB |
Output is correct |
28 |
Correct |
57 ms |
98140 KB |
Output is correct |
29 |
Correct |
50 ms |
98116 KB |
Output is correct |
30 |
Correct |
50 ms |
98124 KB |
Output is correct |
31 |
Correct |
50 ms |
98080 KB |
Output is correct |
32 |
Correct |
51 ms |
98120 KB |
Output is correct |
33 |
Correct |
50 ms |
98116 KB |
Output is correct |
34 |
Correct |
51 ms |
98152 KB |
Output is correct |
35 |
Correct |
51 ms |
98172 KB |
Output is correct |
36 |
Correct |
279 ms |
99020 KB |
Output is correct |
37 |
Correct |
185 ms |
99748 KB |
Output is correct |
38 |
Correct |
150 ms |
100224 KB |
Output is correct |
39 |
Correct |
167 ms |
100576 KB |
Output is correct |
40 |
Correct |
153 ms |
100028 KB |
Output is correct |
41 |
Correct |
87 ms |
99320 KB |
Output is correct |
42 |
Correct |
86 ms |
99228 KB |
Output is correct |
43 |
Correct |
189 ms |
99804 KB |
Output is correct |
44 |
Correct |
50 ms |
98112 KB |
Output is correct |
45 |
Correct |
50 ms |
98128 KB |
Output is correct |
46 |
Correct |
50 ms |
98088 KB |
Output is correct |
47 |
Correct |
50 ms |
98116 KB |
Output is correct |
48 |
Correct |
50 ms |
98048 KB |
Output is correct |
49 |
Correct |
56 ms |
98120 KB |
Output is correct |
50 |
Correct |
55 ms |
98228 KB |
Output is correct |
51 |
Correct |
63 ms |
98196 KB |
Output is correct |
52 |
Correct |
55 ms |
98280 KB |
Output is correct |
53 |
Correct |
287 ms |
99004 KB |
Output is correct |
54 |
Correct |
166 ms |
100404 KB |
Output is correct |
55 |
Correct |
172 ms |
100548 KB |
Output is correct |
56 |
Correct |
171 ms |
100008 KB |
Output is correct |
57 |
Correct |
188 ms |
101476 KB |
Output is correct |
58 |
Correct |
300 ms |
99032 KB |
Output is correct |
59 |
Correct |
208 ms |
99908 KB |
Output is correct |