# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
880418 |
2023-11-29T11:49:47 Z |
VectorLi |
Toll (BOI17_toll) |
C++17 |
|
174 ms |
78936 KB |
#include <bits/stdc++.h>
#define long long long
using namespace std;
const int V = 50000, K = 16;
const int N = 5;
const int MAX = numeric_limits<int>::max();
struct Element {
int a[N][N];
int* operator [] (int i) {
return a[i];
}
Element() {
for (int i = 0; i < N; i++) {
fill(a[i], a[i] + N, MAX);
a[i][i] = 0;
}
}
};
Element operator + (Element &u, Element &v) {
Element w;
for (int i = 0; i < N; i++) {
fill(w[i], w[i] + N, MAX);
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
for (int k = 0; k < N; k++) {
if (u[i][k] < MAX && v[k][j] < MAX) {
w[i][j] = min(w[i][j], u[i][k] + v[k][j]);
}
}
}
}
return w;
}
int n, m, k, q;
Element f[K][V];
void solve() {
cin >> k >> n >> m >> q;
for (int u = 0; u < n / k; u++) {
for (int i = 0; i < N; i++) {
fill(f[0][u][i], f[0][u][i] + N, MAX);
}
}
for (int i = 0; i < m; i++) {
int u, v;
int w;
cin >> u >> v >> w;
f[0][u / k][u % k][v % k] = w;
}
for (int i = 0; i < K - 1; i++) {
for (int u = 0; u < n / k; u++) {
if (u + (1 << i) >= n / k) {
f[i + 1][u] = f[i][u];
} else {
f[i + 1][u] = f[i][u] + f[i][u + (1 << i)];
}
}
}
for (int i = 0; i < q; i++) {
int u, v;
cin >> u >> v;
int p = u / k;
Element x;
for (int j = K - 1; j >= 0; j--) {
if (p + (1 << j) <= v / k) {
x = x + f[j][p];
p = p + (1 << j);
}
}
if (x[u % k][v % k] < MAX) {
cout << x[u % k][v % k] << "\n";
} else {
cout << -1 << "\n";
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
174 ms |
78760 KB |
Output is correct |
2 |
Correct |
17 ms |
78680 KB |
Output is correct |
3 |
Correct |
18 ms |
78580 KB |
Output is correct |
4 |
Correct |
17 ms |
78684 KB |
Output is correct |
5 |
Correct |
20 ms |
78680 KB |
Output is correct |
6 |
Correct |
20 ms |
78684 KB |
Output is correct |
7 |
Correct |
20 ms |
78684 KB |
Output is correct |
8 |
Correct |
153 ms |
78716 KB |
Output is correct |
9 |
Correct |
150 ms |
78684 KB |
Output is correct |
10 |
Correct |
133 ms |
78712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
78712 KB |
Output is correct |
2 |
Correct |
25 ms |
78684 KB |
Output is correct |
3 |
Correct |
17 ms |
78684 KB |
Output is correct |
4 |
Correct |
17 ms |
78684 KB |
Output is correct |
5 |
Correct |
18 ms |
78672 KB |
Output is correct |
6 |
Correct |
17 ms |
78680 KB |
Output is correct |
7 |
Correct |
29 ms |
78736 KB |
Output is correct |
8 |
Correct |
28 ms |
78740 KB |
Output is correct |
9 |
Correct |
142 ms |
78708 KB |
Output is correct |
10 |
Correct |
103 ms |
78720 KB |
Output is correct |
11 |
Correct |
104 ms |
78772 KB |
Output is correct |
12 |
Correct |
82 ms |
78932 KB |
Output is correct |
13 |
Correct |
61 ms |
78684 KB |
Output is correct |
14 |
Correct |
72 ms |
78936 KB |
Output is correct |
15 |
Correct |
53 ms |
78680 KB |
Output is correct |
16 |
Correct |
54 ms |
78684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
78680 KB |
Output is correct |
2 |
Correct |
17 ms |
78684 KB |
Output is correct |
3 |
Correct |
17 ms |
78684 KB |
Output is correct |
4 |
Correct |
17 ms |
78680 KB |
Output is correct |
5 |
Correct |
17 ms |
78544 KB |
Output is correct |
6 |
Correct |
19 ms |
78492 KB |
Output is correct |
7 |
Correct |
18 ms |
78684 KB |
Output is correct |
8 |
Correct |
20 ms |
78576 KB |
Output is correct |
9 |
Correct |
19 ms |
78684 KB |
Output is correct |
10 |
Correct |
144 ms |
78712 KB |
Output is correct |
11 |
Correct |
90 ms |
78712 KB |
Output is correct |
12 |
Correct |
76 ms |
78684 KB |
Output is correct |
13 |
Correct |
83 ms |
78680 KB |
Output is correct |
14 |
Correct |
76 ms |
78684 KB |
Output is correct |
15 |
Correct |
48 ms |
78680 KB |
Output is correct |
16 |
Correct |
49 ms |
78680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
78680 KB |
Output is correct |
2 |
Correct |
17 ms |
78684 KB |
Output is correct |
3 |
Correct |
17 ms |
78684 KB |
Output is correct |
4 |
Correct |
17 ms |
78680 KB |
Output is correct |
5 |
Correct |
17 ms |
78544 KB |
Output is correct |
6 |
Correct |
19 ms |
78492 KB |
Output is correct |
7 |
Correct |
18 ms |
78684 KB |
Output is correct |
8 |
Correct |
20 ms |
78576 KB |
Output is correct |
9 |
Correct |
19 ms |
78684 KB |
Output is correct |
10 |
Correct |
144 ms |
78712 KB |
Output is correct |
11 |
Correct |
90 ms |
78712 KB |
Output is correct |
12 |
Correct |
76 ms |
78684 KB |
Output is correct |
13 |
Correct |
83 ms |
78680 KB |
Output is correct |
14 |
Correct |
76 ms |
78684 KB |
Output is correct |
15 |
Correct |
48 ms |
78680 KB |
Output is correct |
16 |
Correct |
49 ms |
78680 KB |
Output is correct |
17 |
Correct |
100 ms |
78712 KB |
Output is correct |
18 |
Correct |
17 ms |
78680 KB |
Output is correct |
19 |
Correct |
17 ms |
78680 KB |
Output is correct |
20 |
Correct |
18 ms |
78680 KB |
Output is correct |
21 |
Correct |
18 ms |
78684 KB |
Output is correct |
22 |
Correct |
21 ms |
78528 KB |
Output is correct |
23 |
Correct |
22 ms |
78540 KB |
Output is correct |
24 |
Correct |
21 ms |
78568 KB |
Output is correct |
25 |
Correct |
21 ms |
78680 KB |
Output is correct |
26 |
Correct |
21 ms |
78692 KB |
Output is correct |
27 |
Correct |
143 ms |
78720 KB |
Output is correct |
28 |
Correct |
82 ms |
78676 KB |
Output is correct |
29 |
Correct |
106 ms |
78728 KB |
Output is correct |
30 |
Correct |
81 ms |
78684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
174 ms |
78760 KB |
Output is correct |
2 |
Correct |
17 ms |
78680 KB |
Output is correct |
3 |
Correct |
18 ms |
78580 KB |
Output is correct |
4 |
Correct |
17 ms |
78684 KB |
Output is correct |
5 |
Correct |
20 ms |
78680 KB |
Output is correct |
6 |
Correct |
20 ms |
78684 KB |
Output is correct |
7 |
Correct |
20 ms |
78684 KB |
Output is correct |
8 |
Correct |
153 ms |
78716 KB |
Output is correct |
9 |
Correct |
150 ms |
78684 KB |
Output is correct |
10 |
Correct |
133 ms |
78712 KB |
Output is correct |
11 |
Correct |
102 ms |
78712 KB |
Output is correct |
12 |
Correct |
25 ms |
78684 KB |
Output is correct |
13 |
Correct |
17 ms |
78684 KB |
Output is correct |
14 |
Correct |
17 ms |
78684 KB |
Output is correct |
15 |
Correct |
18 ms |
78672 KB |
Output is correct |
16 |
Correct |
17 ms |
78680 KB |
Output is correct |
17 |
Correct |
29 ms |
78736 KB |
Output is correct |
18 |
Correct |
28 ms |
78740 KB |
Output is correct |
19 |
Correct |
142 ms |
78708 KB |
Output is correct |
20 |
Correct |
103 ms |
78720 KB |
Output is correct |
21 |
Correct |
104 ms |
78772 KB |
Output is correct |
22 |
Correct |
82 ms |
78932 KB |
Output is correct |
23 |
Correct |
61 ms |
78684 KB |
Output is correct |
24 |
Correct |
72 ms |
78936 KB |
Output is correct |
25 |
Correct |
53 ms |
78680 KB |
Output is correct |
26 |
Correct |
54 ms |
78684 KB |
Output is correct |
27 |
Correct |
17 ms |
78680 KB |
Output is correct |
28 |
Correct |
17 ms |
78684 KB |
Output is correct |
29 |
Correct |
17 ms |
78684 KB |
Output is correct |
30 |
Correct |
17 ms |
78680 KB |
Output is correct |
31 |
Correct |
17 ms |
78544 KB |
Output is correct |
32 |
Correct |
19 ms |
78492 KB |
Output is correct |
33 |
Correct |
18 ms |
78684 KB |
Output is correct |
34 |
Correct |
20 ms |
78576 KB |
Output is correct |
35 |
Correct |
19 ms |
78684 KB |
Output is correct |
36 |
Correct |
144 ms |
78712 KB |
Output is correct |
37 |
Correct |
90 ms |
78712 KB |
Output is correct |
38 |
Correct |
76 ms |
78684 KB |
Output is correct |
39 |
Correct |
83 ms |
78680 KB |
Output is correct |
40 |
Correct |
76 ms |
78684 KB |
Output is correct |
41 |
Correct |
48 ms |
78680 KB |
Output is correct |
42 |
Correct |
49 ms |
78680 KB |
Output is correct |
43 |
Correct |
100 ms |
78712 KB |
Output is correct |
44 |
Correct |
17 ms |
78680 KB |
Output is correct |
45 |
Correct |
17 ms |
78680 KB |
Output is correct |
46 |
Correct |
18 ms |
78680 KB |
Output is correct |
47 |
Correct |
18 ms |
78684 KB |
Output is correct |
48 |
Correct |
21 ms |
78528 KB |
Output is correct |
49 |
Correct |
22 ms |
78540 KB |
Output is correct |
50 |
Correct |
21 ms |
78568 KB |
Output is correct |
51 |
Correct |
21 ms |
78680 KB |
Output is correct |
52 |
Correct |
21 ms |
78692 KB |
Output is correct |
53 |
Correct |
143 ms |
78720 KB |
Output is correct |
54 |
Correct |
82 ms |
78676 KB |
Output is correct |
55 |
Correct |
106 ms |
78728 KB |
Output is correct |
56 |
Correct |
81 ms |
78684 KB |
Output is correct |
57 |
Correct |
99 ms |
78744 KB |
Output is correct |
58 |
Correct |
156 ms |
78932 KB |
Output is correct |
59 |
Correct |
109 ms |
78680 KB |
Output is correct |