# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1092906 |
2024-09-25T10:49:57 Z |
juicy |
Toll (BOI17_toll) |
C++17 |
|
66 ms |
25476 KB |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 5e4, inf = 1e9;
struct Node {
int a[5][5];
Node() {
for (int i = 0; i < 5; ++i) {
for (int j = 0; j < 5; ++j) {
a[i][j] = inf;
}
}
}
Node operator + (const Node &o) const {
Node res;
for (int i = 0; i < 5; ++i) {
for (int j = 0; j < 5; ++j) {
for (int k = 0; k < 5; ++k) {
res.a[i][k] = min(res.a[i][k], a[i][j] + o.a[j][k]);
}
}
}
return res;
}
};
int k, n, m, o;
int c[N][5];
Node s[4 * N];
vector<array<int, 2>> g[N];
void bld(int id = 1, int l = 0, int r = n / k - 1) {
if (l == r) {
for (int i = 0; i < k; ++i) {
int ii = l * k + i;
for (int j = 0; j < k; ++j) {
s[id].a[i][j] = !c[ii][j] ? inf : c[ii][j];
}
}
return;
}
int m = (l + r) / 2;
bld(id * 2, l, m);
bld(id * 2 + 1, m + 1, r);
s[id] = s[id * 2] + s[id * 2 + 1];
}
Node qry(int u, int v, int id = 1, int l = 0, int r = n / k - 1) {
if (u <= l && r <= v) {
return s[id];
}
int m = (l + r) / 2;
if (v <= m) {
return qry(u, v, id * 2, l, m);
}
if (m < u) {
return qry(u, v, id * 2 + 1, m + 1, r);
}
return qry(u, v, id * 2, l, m) + qry(u, v, id * 2 + 1, m + 1, r);
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> k >> n >> m >> o;
while (m--) {
int a, b, w; cin >> a >> b >> w;
c[a][b % k] = w;
}
bld();
while (o--) {
int a, b; cin >> a >> b;
if (a / k == b / k) {
cout << -1 << "\n";
} else {
auto d = qry(a / k, b / k - 1);
int res = d.a[a % k][b % k];
cout << (res == inf ? -1 : res) << "\n";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
23152 KB |
Output is correct |
2 |
Correct |
8 ms |
21088 KB |
Output is correct |
3 |
Correct |
8 ms |
21088 KB |
Output is correct |
4 |
Correct |
8 ms |
21020 KB |
Output is correct |
5 |
Correct |
11 ms |
21084 KB |
Output is correct |
6 |
Correct |
9 ms |
21196 KB |
Output is correct |
7 |
Correct |
10 ms |
21080 KB |
Output is correct |
8 |
Correct |
45 ms |
23100 KB |
Output is correct |
9 |
Correct |
42 ms |
23060 KB |
Output is correct |
10 |
Correct |
35 ms |
21328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
23640 KB |
Output is correct |
2 |
Correct |
9 ms |
21084 KB |
Output is correct |
3 |
Correct |
9 ms |
21080 KB |
Output is correct |
4 |
Correct |
10 ms |
21084 KB |
Output is correct |
5 |
Correct |
9 ms |
21080 KB |
Output is correct |
6 |
Correct |
8 ms |
21084 KB |
Output is correct |
7 |
Correct |
16 ms |
21248 KB |
Output is correct |
8 |
Correct |
18 ms |
21336 KB |
Output is correct |
9 |
Correct |
35 ms |
23064 KB |
Output is correct |
10 |
Correct |
40 ms |
24412 KB |
Output is correct |
11 |
Correct |
40 ms |
23688 KB |
Output is correct |
12 |
Correct |
38 ms |
23388 KB |
Output is correct |
13 |
Correct |
37 ms |
24144 KB |
Output is correct |
14 |
Correct |
27 ms |
23128 KB |
Output is correct |
15 |
Correct |
24 ms |
22876 KB |
Output is correct |
16 |
Correct |
24 ms |
22876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
21080 KB |
Output is correct |
2 |
Correct |
9 ms |
21084 KB |
Output is correct |
3 |
Correct |
9 ms |
20980 KB |
Output is correct |
4 |
Correct |
9 ms |
21084 KB |
Output is correct |
5 |
Correct |
8 ms |
21084 KB |
Output is correct |
6 |
Correct |
9 ms |
21084 KB |
Output is correct |
7 |
Correct |
9 ms |
21084 KB |
Output is correct |
8 |
Correct |
9 ms |
21084 KB |
Output is correct |
9 |
Correct |
9 ms |
21096 KB |
Output is correct |
10 |
Correct |
25 ms |
22932 KB |
Output is correct |
11 |
Correct |
30 ms |
23632 KB |
Output is correct |
12 |
Correct |
34 ms |
24144 KB |
Output is correct |
13 |
Correct |
35 ms |
24400 KB |
Output is correct |
14 |
Correct |
27 ms |
23896 KB |
Output is correct |
15 |
Correct |
22 ms |
22872 KB |
Output is correct |
16 |
Correct |
20 ms |
22920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
21080 KB |
Output is correct |
2 |
Correct |
9 ms |
21084 KB |
Output is correct |
3 |
Correct |
9 ms |
20980 KB |
Output is correct |
4 |
Correct |
9 ms |
21084 KB |
Output is correct |
5 |
Correct |
8 ms |
21084 KB |
Output is correct |
6 |
Correct |
9 ms |
21084 KB |
Output is correct |
7 |
Correct |
9 ms |
21084 KB |
Output is correct |
8 |
Correct |
9 ms |
21084 KB |
Output is correct |
9 |
Correct |
9 ms |
21096 KB |
Output is correct |
10 |
Correct |
25 ms |
22932 KB |
Output is correct |
11 |
Correct |
30 ms |
23632 KB |
Output is correct |
12 |
Correct |
34 ms |
24144 KB |
Output is correct |
13 |
Correct |
35 ms |
24400 KB |
Output is correct |
14 |
Correct |
27 ms |
23896 KB |
Output is correct |
15 |
Correct |
22 ms |
22872 KB |
Output is correct |
16 |
Correct |
20 ms |
22920 KB |
Output is correct |
17 |
Correct |
34 ms |
23632 KB |
Output is correct |
18 |
Correct |
9 ms |
21092 KB |
Output is correct |
19 |
Correct |
9 ms |
21076 KB |
Output is correct |
20 |
Correct |
9 ms |
21084 KB |
Output is correct |
21 |
Correct |
9 ms |
21084 KB |
Output is correct |
22 |
Correct |
9 ms |
21084 KB |
Output is correct |
23 |
Correct |
16 ms |
21228 KB |
Output is correct |
24 |
Correct |
12 ms |
21084 KB |
Output is correct |
25 |
Correct |
12 ms |
21080 KB |
Output is correct |
26 |
Correct |
11 ms |
21240 KB |
Output is correct |
27 |
Correct |
29 ms |
22788 KB |
Output is correct |
28 |
Correct |
39 ms |
24144 KB |
Output is correct |
29 |
Correct |
40 ms |
24600 KB |
Output is correct |
30 |
Correct |
33 ms |
23888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
23152 KB |
Output is correct |
2 |
Correct |
8 ms |
21088 KB |
Output is correct |
3 |
Correct |
8 ms |
21088 KB |
Output is correct |
4 |
Correct |
8 ms |
21020 KB |
Output is correct |
5 |
Correct |
11 ms |
21084 KB |
Output is correct |
6 |
Correct |
9 ms |
21196 KB |
Output is correct |
7 |
Correct |
10 ms |
21080 KB |
Output is correct |
8 |
Correct |
45 ms |
23100 KB |
Output is correct |
9 |
Correct |
42 ms |
23060 KB |
Output is correct |
10 |
Correct |
35 ms |
21328 KB |
Output is correct |
11 |
Correct |
39 ms |
23640 KB |
Output is correct |
12 |
Correct |
9 ms |
21084 KB |
Output is correct |
13 |
Correct |
9 ms |
21080 KB |
Output is correct |
14 |
Correct |
10 ms |
21084 KB |
Output is correct |
15 |
Correct |
9 ms |
21080 KB |
Output is correct |
16 |
Correct |
8 ms |
21084 KB |
Output is correct |
17 |
Correct |
16 ms |
21248 KB |
Output is correct |
18 |
Correct |
18 ms |
21336 KB |
Output is correct |
19 |
Correct |
35 ms |
23064 KB |
Output is correct |
20 |
Correct |
40 ms |
24412 KB |
Output is correct |
21 |
Correct |
40 ms |
23688 KB |
Output is correct |
22 |
Correct |
38 ms |
23388 KB |
Output is correct |
23 |
Correct |
37 ms |
24144 KB |
Output is correct |
24 |
Correct |
27 ms |
23128 KB |
Output is correct |
25 |
Correct |
24 ms |
22876 KB |
Output is correct |
26 |
Correct |
24 ms |
22876 KB |
Output is correct |
27 |
Correct |
9 ms |
21080 KB |
Output is correct |
28 |
Correct |
9 ms |
21084 KB |
Output is correct |
29 |
Correct |
9 ms |
20980 KB |
Output is correct |
30 |
Correct |
9 ms |
21084 KB |
Output is correct |
31 |
Correct |
8 ms |
21084 KB |
Output is correct |
32 |
Correct |
9 ms |
21084 KB |
Output is correct |
33 |
Correct |
9 ms |
21084 KB |
Output is correct |
34 |
Correct |
9 ms |
21084 KB |
Output is correct |
35 |
Correct |
9 ms |
21096 KB |
Output is correct |
36 |
Correct |
25 ms |
22932 KB |
Output is correct |
37 |
Correct |
30 ms |
23632 KB |
Output is correct |
38 |
Correct |
34 ms |
24144 KB |
Output is correct |
39 |
Correct |
35 ms |
24400 KB |
Output is correct |
40 |
Correct |
27 ms |
23896 KB |
Output is correct |
41 |
Correct |
22 ms |
22872 KB |
Output is correct |
42 |
Correct |
20 ms |
22920 KB |
Output is correct |
43 |
Correct |
34 ms |
23632 KB |
Output is correct |
44 |
Correct |
9 ms |
21092 KB |
Output is correct |
45 |
Correct |
9 ms |
21076 KB |
Output is correct |
46 |
Correct |
9 ms |
21084 KB |
Output is correct |
47 |
Correct |
9 ms |
21084 KB |
Output is correct |
48 |
Correct |
9 ms |
21084 KB |
Output is correct |
49 |
Correct |
16 ms |
21228 KB |
Output is correct |
50 |
Correct |
12 ms |
21084 KB |
Output is correct |
51 |
Correct |
12 ms |
21080 KB |
Output is correct |
52 |
Correct |
11 ms |
21240 KB |
Output is correct |
53 |
Correct |
29 ms |
22788 KB |
Output is correct |
54 |
Correct |
39 ms |
24144 KB |
Output is correct |
55 |
Correct |
40 ms |
24600 KB |
Output is correct |
56 |
Correct |
33 ms |
23888 KB |
Output is correct |
57 |
Correct |
66 ms |
25476 KB |
Output is correct |
58 |
Correct |
50 ms |
22872 KB |
Output is correct |
59 |
Correct |
47 ms |
23888 KB |
Output is correct |