# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
491279 |
2021-12-01T10:07:29 Z |
Rainbowbunny |
Toll (BOI17_toll) |
C++17 |
|
88 ms |
28048 KB |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MAXN = 5e4 + 5;
int lim = 5;
struct Node
{
int a[5][5];
Node()
{
for(int i = 0; i < lim; i++)
{
for(int j = 0; j < lim; j++)
{
if(i == j)
{
a[i][j] = INF;
}
else
{
a[i][j] = INF;
}
}
}
}
};
void Print(Node X)
{
for(int i = 0; i < lim; i++)
{
for(int j = 0; j < lim; j++)
{
cout << X.a[i][j] << ' ';
}
cout << '\n';
}
cout << '\n';
}
Node Merge(Node A, Node B)
{
Node C;
for(int i = 0; i < lim; i++)
{
for(int j = 0; j < lim; j++)
{
for(int k = 0; k < lim; k++)
{
C.a[i][j] = min(C.a[i][j], A.a[i][k] + B.a[k][j]);
}
}
}
return C;
}
int n, q, m;
Node Block[MAXN];
Node IT[4 * MAXN];
void Build(int node, int l, int r)
{
if(l == r)
{
IT[node] = Block[l];
return;
}
int mid = (l + r) >> 1;
Build(node << 1, l, mid);
Build(node << 1 | 1, mid + 1, r);
IT[node] = Merge(IT[node << 1], IT[node << 1 | 1]);
}
Node Get(int node, int l, int r, int L, int R)
{
if(l > R or r < L or L > R)
{
Node tmp;
for(int i = 0; i < lim; i++)
{
tmp.a[i][i] = 0;
}
return tmp;
}
if(L <= l and r <= R)
{
return IT[node];
}
int mid = (l + r) >> 1;
return Merge(Get(node << 1, l, mid, L, R), Get(node << 1 | 1, mid + 1, r, L, R));
}
int main()
{
// freopen("Input.txt", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> lim >> n >> m >> q;
for(int i = 1; i <= m; i++)
{
int u, v, c;
cin >> u >> v >> c;
Block[u / lim].a[u % lim][v % lim] = min(Block[u / lim].a[u % lim][v % lim], c);
}
int tmp = n / lim;
Build(1, 0, tmp);
while(q--)
{
int x, y;
cin >> x >> y;
if(x / lim > y / lim - 1)
{
cout << -1 << '\n';
continue;
}
Node tt = Get(1, 0, tmp, x / lim, y / lim - 1);
if(tt.a[x % lim][y % lim] == INF)
{
tt.a[x % lim][y % lim] = -1;
}
cout << tt.a[x % lim][y % lim] << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
24764 KB |
Output is correct |
2 |
Correct |
14 ms |
24668 KB |
Output is correct |
3 |
Correct |
14 ms |
24652 KB |
Output is correct |
4 |
Correct |
14 ms |
24680 KB |
Output is correct |
5 |
Correct |
15 ms |
24780 KB |
Output is correct |
6 |
Correct |
14 ms |
24788 KB |
Output is correct |
7 |
Correct |
15 ms |
24788 KB |
Output is correct |
8 |
Correct |
44 ms |
25664 KB |
Output is correct |
9 |
Correct |
53 ms |
25644 KB |
Output is correct |
10 |
Correct |
27 ms |
24796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
25016 KB |
Output is correct |
2 |
Correct |
14 ms |
24720 KB |
Output is correct |
3 |
Correct |
14 ms |
24676 KB |
Output is correct |
4 |
Correct |
13 ms |
24652 KB |
Output is correct |
5 |
Correct |
14 ms |
24756 KB |
Output is correct |
6 |
Correct |
14 ms |
24716 KB |
Output is correct |
7 |
Correct |
20 ms |
24856 KB |
Output is correct |
8 |
Correct |
19 ms |
24888 KB |
Output is correct |
9 |
Correct |
37 ms |
25560 KB |
Output is correct |
10 |
Correct |
73 ms |
27076 KB |
Output is correct |
11 |
Correct |
46 ms |
26440 KB |
Output is correct |
12 |
Correct |
41 ms |
26052 KB |
Output is correct |
13 |
Correct |
56 ms |
27136 KB |
Output is correct |
14 |
Correct |
38 ms |
26180 KB |
Output is correct |
15 |
Correct |
37 ms |
25908 KB |
Output is correct |
16 |
Correct |
40 ms |
25964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
24700 KB |
Output is correct |
2 |
Correct |
16 ms |
24764 KB |
Output is correct |
3 |
Correct |
13 ms |
24652 KB |
Output is correct |
4 |
Correct |
14 ms |
24776 KB |
Output is correct |
5 |
Correct |
14 ms |
24668 KB |
Output is correct |
6 |
Correct |
15 ms |
24780 KB |
Output is correct |
7 |
Correct |
14 ms |
24780 KB |
Output is correct |
8 |
Correct |
14 ms |
24784 KB |
Output is correct |
9 |
Correct |
14 ms |
24780 KB |
Output is correct |
10 |
Correct |
30 ms |
25532 KB |
Output is correct |
11 |
Correct |
37 ms |
26180 KB |
Output is correct |
12 |
Correct |
45 ms |
26932 KB |
Output is correct |
13 |
Correct |
54 ms |
27172 KB |
Output is correct |
14 |
Correct |
52 ms |
26552 KB |
Output is correct |
15 |
Correct |
33 ms |
25936 KB |
Output is correct |
16 |
Correct |
32 ms |
25924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
24700 KB |
Output is correct |
2 |
Correct |
16 ms |
24764 KB |
Output is correct |
3 |
Correct |
13 ms |
24652 KB |
Output is correct |
4 |
Correct |
14 ms |
24776 KB |
Output is correct |
5 |
Correct |
14 ms |
24668 KB |
Output is correct |
6 |
Correct |
15 ms |
24780 KB |
Output is correct |
7 |
Correct |
14 ms |
24780 KB |
Output is correct |
8 |
Correct |
14 ms |
24784 KB |
Output is correct |
9 |
Correct |
14 ms |
24780 KB |
Output is correct |
10 |
Correct |
30 ms |
25532 KB |
Output is correct |
11 |
Correct |
37 ms |
26180 KB |
Output is correct |
12 |
Correct |
45 ms |
26932 KB |
Output is correct |
13 |
Correct |
54 ms |
27172 KB |
Output is correct |
14 |
Correct |
52 ms |
26552 KB |
Output is correct |
15 |
Correct |
33 ms |
25936 KB |
Output is correct |
16 |
Correct |
32 ms |
25924 KB |
Output is correct |
17 |
Correct |
41 ms |
26336 KB |
Output is correct |
18 |
Correct |
21 ms |
24752 KB |
Output is correct |
19 |
Correct |
15 ms |
24776 KB |
Output is correct |
20 |
Correct |
14 ms |
24672 KB |
Output is correct |
21 |
Correct |
17 ms |
24760 KB |
Output is correct |
22 |
Correct |
14 ms |
24684 KB |
Output is correct |
23 |
Correct |
16 ms |
24828 KB |
Output is correct |
24 |
Correct |
16 ms |
24788 KB |
Output is correct |
25 |
Correct |
21 ms |
24832 KB |
Output is correct |
26 |
Correct |
20 ms |
24780 KB |
Output is correct |
27 |
Correct |
32 ms |
25520 KB |
Output is correct |
28 |
Correct |
51 ms |
26936 KB |
Output is correct |
29 |
Correct |
53 ms |
27184 KB |
Output is correct |
30 |
Correct |
46 ms |
26624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
24764 KB |
Output is correct |
2 |
Correct |
14 ms |
24668 KB |
Output is correct |
3 |
Correct |
14 ms |
24652 KB |
Output is correct |
4 |
Correct |
14 ms |
24680 KB |
Output is correct |
5 |
Correct |
15 ms |
24780 KB |
Output is correct |
6 |
Correct |
14 ms |
24788 KB |
Output is correct |
7 |
Correct |
15 ms |
24788 KB |
Output is correct |
8 |
Correct |
44 ms |
25664 KB |
Output is correct |
9 |
Correct |
53 ms |
25644 KB |
Output is correct |
10 |
Correct |
27 ms |
24796 KB |
Output is correct |
11 |
Correct |
44 ms |
25016 KB |
Output is correct |
12 |
Correct |
14 ms |
24720 KB |
Output is correct |
13 |
Correct |
14 ms |
24676 KB |
Output is correct |
14 |
Correct |
13 ms |
24652 KB |
Output is correct |
15 |
Correct |
14 ms |
24756 KB |
Output is correct |
16 |
Correct |
14 ms |
24716 KB |
Output is correct |
17 |
Correct |
20 ms |
24856 KB |
Output is correct |
18 |
Correct |
19 ms |
24888 KB |
Output is correct |
19 |
Correct |
37 ms |
25560 KB |
Output is correct |
20 |
Correct |
73 ms |
27076 KB |
Output is correct |
21 |
Correct |
46 ms |
26440 KB |
Output is correct |
22 |
Correct |
41 ms |
26052 KB |
Output is correct |
23 |
Correct |
56 ms |
27136 KB |
Output is correct |
24 |
Correct |
38 ms |
26180 KB |
Output is correct |
25 |
Correct |
37 ms |
25908 KB |
Output is correct |
26 |
Correct |
40 ms |
25964 KB |
Output is correct |
27 |
Correct |
14 ms |
24700 KB |
Output is correct |
28 |
Correct |
16 ms |
24764 KB |
Output is correct |
29 |
Correct |
13 ms |
24652 KB |
Output is correct |
30 |
Correct |
14 ms |
24776 KB |
Output is correct |
31 |
Correct |
14 ms |
24668 KB |
Output is correct |
32 |
Correct |
15 ms |
24780 KB |
Output is correct |
33 |
Correct |
14 ms |
24780 KB |
Output is correct |
34 |
Correct |
14 ms |
24784 KB |
Output is correct |
35 |
Correct |
14 ms |
24780 KB |
Output is correct |
36 |
Correct |
30 ms |
25532 KB |
Output is correct |
37 |
Correct |
37 ms |
26180 KB |
Output is correct |
38 |
Correct |
45 ms |
26932 KB |
Output is correct |
39 |
Correct |
54 ms |
27172 KB |
Output is correct |
40 |
Correct |
52 ms |
26552 KB |
Output is correct |
41 |
Correct |
33 ms |
25936 KB |
Output is correct |
42 |
Correct |
32 ms |
25924 KB |
Output is correct |
43 |
Correct |
41 ms |
26336 KB |
Output is correct |
44 |
Correct |
21 ms |
24752 KB |
Output is correct |
45 |
Correct |
15 ms |
24776 KB |
Output is correct |
46 |
Correct |
14 ms |
24672 KB |
Output is correct |
47 |
Correct |
17 ms |
24760 KB |
Output is correct |
48 |
Correct |
14 ms |
24684 KB |
Output is correct |
49 |
Correct |
16 ms |
24828 KB |
Output is correct |
50 |
Correct |
16 ms |
24788 KB |
Output is correct |
51 |
Correct |
21 ms |
24832 KB |
Output is correct |
52 |
Correct |
20 ms |
24780 KB |
Output is correct |
53 |
Correct |
32 ms |
25520 KB |
Output is correct |
54 |
Correct |
51 ms |
26936 KB |
Output is correct |
55 |
Correct |
53 ms |
27184 KB |
Output is correct |
56 |
Correct |
46 ms |
26624 KB |
Output is correct |
57 |
Correct |
88 ms |
28048 KB |
Output is correct |
58 |
Correct |
42 ms |
25676 KB |
Output is correct |
59 |
Correct |
50 ms |
26552 KB |
Output is correct |