# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
836366 |
2023-08-24T10:37:43 Z |
lamduybao03 |
Toll (BOI17_toll) |
C++14 |
|
222 ms |
60016 KB |
#include <bits/stdc++.h>
#define int long long
#define sqr(x) ((x) * (x))
using namespace std;
typedef pair<int, int> pi;
typedef pair<pi, int> ppi;
const int mod = 1e9+7;
const int inv_2 = (mod+1) / 2;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
int k, n, m, o;
cin >> k >> n >> m >> o;
int p[n+1][k][18];
int toll[n+1][k][18];
fill(p[0][0], p[n+1][0], n);
memset(toll, 0x3f, sizeof(toll));
for(int i = 0; i < m; i++) {
int a, b, t;
cin >> a >> b >> t;
p[b][a%k][0] = a;
toll[b][a%k][0] = t;
}
for(int x = 1; x < 18; x++) {
for(int u = 0; u < n; u++) {
for(int i = 0; i < k; i++) {
int v = p[u][i][x-1];
for(int j = 0; j < k; j++) {
p[u][j][x] = min(p[u][j][x], p[v][j][x-1]);
toll[u][j][x] = min(toll[u][j][x], toll[u][i][x-1] + toll[v][j][x-1]);
}
}
}
}
while(o--) {
int a, b;
cin >> a >> b;
int delta = b / k - a / k;
int dis[k];
fill(dis, dis+k, 1e18);
dis[b % k] = 0;
int id = b / k;
for(int i = 0; i < 18; i++) {
if(delta & (1 << i)) {
int tmp[k];
fill(tmp, tmp+k, 1e18);
for(int j = 0; j < k; j++) {
for(int x = 0; x < k; x++) {
tmp[x] = min(tmp[x], dis[j] + toll[id*k+j][x][i]);
}
}
id -= (1 << i);
for(int j = 0; j < k; j++) {
dis[j] = tmp[j];
}
}
}
int ans = dis[a%k];
if(ans > 1e17)
cout << "-1\n";
else {
cout << ans << "\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
15308 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
30 ms |
15288 KB |
Output is correct |
9 |
Correct |
32 ms |
15260 KB |
Output is correct |
10 |
Correct |
18 ms |
14548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
30028 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
3 ms |
596 KB |
Output is correct |
8 |
Correct |
4 ms |
1024 KB |
Output is correct |
9 |
Correct |
30 ms |
15296 KB |
Output is correct |
10 |
Correct |
159 ms |
44852 KB |
Output is correct |
11 |
Correct |
85 ms |
30256 KB |
Output is correct |
12 |
Correct |
154 ms |
43832 KB |
Output is correct |
13 |
Correct |
166 ms |
44952 KB |
Output is correct |
14 |
Correct |
96 ms |
27048 KB |
Output is correct |
15 |
Correct |
136 ms |
43772 KB |
Output is correct |
16 |
Correct |
134 ms |
43856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
852 KB |
Output is correct |
8 |
Correct |
5 ms |
1748 KB |
Output is correct |
9 |
Correct |
2 ms |
1496 KB |
Output is correct |
10 |
Correct |
27 ms |
15148 KB |
Output is correct |
11 |
Correct |
77 ms |
30000 KB |
Output is correct |
12 |
Correct |
151 ms |
44628 KB |
Output is correct |
13 |
Correct |
156 ms |
44984 KB |
Output is correct |
14 |
Correct |
144 ms |
44340 KB |
Output is correct |
15 |
Correct |
130 ms |
43752 KB |
Output is correct |
16 |
Correct |
128 ms |
43692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
852 KB |
Output is correct |
8 |
Correct |
5 ms |
1748 KB |
Output is correct |
9 |
Correct |
2 ms |
1496 KB |
Output is correct |
10 |
Correct |
27 ms |
15148 KB |
Output is correct |
11 |
Correct |
77 ms |
30000 KB |
Output is correct |
12 |
Correct |
151 ms |
44628 KB |
Output is correct |
13 |
Correct |
156 ms |
44984 KB |
Output is correct |
14 |
Correct |
144 ms |
44340 KB |
Output is correct |
15 |
Correct |
130 ms |
43752 KB |
Output is correct |
16 |
Correct |
128 ms |
43692 KB |
Output is correct |
17 |
Correct |
85 ms |
30032 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
540 KB |
Output is correct |
24 |
Correct |
2 ms |
852 KB |
Output is correct |
25 |
Correct |
3 ms |
1736 KB |
Output is correct |
26 |
Correct |
3 ms |
1492 KB |
Output is correct |
27 |
Correct |
30 ms |
15236 KB |
Output is correct |
28 |
Correct |
155 ms |
44728 KB |
Output is correct |
29 |
Correct |
153 ms |
45004 KB |
Output is correct |
30 |
Correct |
147 ms |
44408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
15308 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
30 ms |
15288 KB |
Output is correct |
9 |
Correct |
32 ms |
15260 KB |
Output is correct |
10 |
Correct |
18 ms |
14548 KB |
Output is correct |
11 |
Correct |
81 ms |
30028 KB |
Output is correct |
12 |
Correct |
0 ms |
320 KB |
Output is correct |
13 |
Correct |
0 ms |
316 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
3 ms |
596 KB |
Output is correct |
18 |
Correct |
4 ms |
1024 KB |
Output is correct |
19 |
Correct |
30 ms |
15296 KB |
Output is correct |
20 |
Correct |
159 ms |
44852 KB |
Output is correct |
21 |
Correct |
85 ms |
30256 KB |
Output is correct |
22 |
Correct |
154 ms |
43832 KB |
Output is correct |
23 |
Correct |
166 ms |
44952 KB |
Output is correct |
24 |
Correct |
96 ms |
27048 KB |
Output is correct |
25 |
Correct |
136 ms |
43772 KB |
Output is correct |
26 |
Correct |
134 ms |
43856 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
320 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
324 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
596 KB |
Output is correct |
33 |
Correct |
1 ms |
852 KB |
Output is correct |
34 |
Correct |
5 ms |
1748 KB |
Output is correct |
35 |
Correct |
2 ms |
1496 KB |
Output is correct |
36 |
Correct |
27 ms |
15148 KB |
Output is correct |
37 |
Correct |
77 ms |
30000 KB |
Output is correct |
38 |
Correct |
151 ms |
44628 KB |
Output is correct |
39 |
Correct |
156 ms |
44984 KB |
Output is correct |
40 |
Correct |
144 ms |
44340 KB |
Output is correct |
41 |
Correct |
130 ms |
43752 KB |
Output is correct |
42 |
Correct |
128 ms |
43692 KB |
Output is correct |
43 |
Correct |
85 ms |
30032 KB |
Output is correct |
44 |
Correct |
0 ms |
212 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
540 KB |
Output is correct |
50 |
Correct |
2 ms |
852 KB |
Output is correct |
51 |
Correct |
3 ms |
1736 KB |
Output is correct |
52 |
Correct |
3 ms |
1492 KB |
Output is correct |
53 |
Correct |
30 ms |
15236 KB |
Output is correct |
54 |
Correct |
155 ms |
44728 KB |
Output is correct |
55 |
Correct |
153 ms |
45004 KB |
Output is correct |
56 |
Correct |
147 ms |
44408 KB |
Output is correct |
57 |
Correct |
222 ms |
60016 KB |
Output is correct |
58 |
Correct |
29 ms |
15308 KB |
Output is correct |
59 |
Correct |
90 ms |
30284 KB |
Output is correct |