# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1092904 |
2024-09-25T10:35:45 Z |
juicy |
Toll (BOI17_toll) |
C++17 |
|
241 ms |
105784 KB |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 5e4, B = 100, inf = 1e9;
int k, n, m, o;
int d[N][500], blk[N], lt[500], rt[500], nxt[N];
vector<array<int, 2>> g[N];
int qry(vector<array<int, 2>> a, int b) {
int id = blk[a[0][0]];
if (id == blk[b]) {
int res = inf;
b -= lt[id];
for (auto [u, c] : a) {
if (d[u][b] < inf) {
res = min(res, c + d[u][b]);
}
}
return res == inf ? -1 : res;
}
fill(nxt + rt[id] + 1, nxt + rt[id] + 1 + k, inf);
for (int i = rt[id] - k + 1; i <= rt[id]; ++i) {
int k = i - lt[id], cur = inf;
for (auto [u, c] : a) {
if (d[u][k] < inf) {
cur = min(cur, c + d[u][k]);
}
}
if (cur != inf) {
for (auto [v, c] : g[i]) {
nxt[v] = min(nxt[v], cur + c);
}
}
}
vector<array<int, 2>> nw;
for (int i = rt[id] + 1; i <= rt[id] + k; ++i) {
if (nxt[i] != inf) {
nw.push_back({i, nxt[i]});
}
}
return !nw.size() ? -1 : qry(nw, b);
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> k >> n >> m >> o;
for (int i = 0; i < n; ++i) {
blk[i] = i / k / B;
rt[blk[i]] = i;
}
for (int i = n - 1; ~i; --i) {
lt[blk[i]] = i;
}
while (m--) {
int a, b, c; cin >> a >> b >> c;
g[a].push_back({b, c});
}
memset(d, 0x3f, sizeof(d));
for (int i = 0; i < n; ++i) {
int id = blk[i];
d[i][i - lt[id]] = 0;
for (int j = i; blk[j] == id; ++j) {
int jj = j - lt[id];
if (d[i][jj] < inf) {
for (auto [k, w] : g[j]) {
if (k <= rt[id]) {
int kk = k - lt[id];
d[i][kk] = min(d[i][kk], d[i][jj] + w);
}
}
}
}
}
while (o--) {
int a, b; cin >> a >> b;
cout << qry({{a, 0}}, b) << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
181 ms |
102480 KB |
Output is correct |
2 |
Correct |
47 ms |
99412 KB |
Output is correct |
3 |
Correct |
49 ms |
99416 KB |
Output is correct |
4 |
Correct |
49 ms |
99360 KB |
Output is correct |
5 |
Correct |
47 ms |
99468 KB |
Output is correct |
6 |
Correct |
50 ms |
99356 KB |
Output is correct |
7 |
Correct |
48 ms |
99412 KB |
Output is correct |
8 |
Correct |
76 ms |
102228 KB |
Output is correct |
9 |
Correct |
71 ms |
102072 KB |
Output is correct |
10 |
Correct |
55 ms |
99920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
173 ms |
102736 KB |
Output is correct |
2 |
Correct |
45 ms |
99408 KB |
Output is correct |
3 |
Correct |
44 ms |
99412 KB |
Output is correct |
4 |
Correct |
43 ms |
99408 KB |
Output is correct |
5 |
Correct |
45 ms |
99408 KB |
Output is correct |
6 |
Correct |
47 ms |
99408 KB |
Output is correct |
7 |
Correct |
42 ms |
99420 KB |
Output is correct |
8 |
Correct |
47 ms |
99544 KB |
Output is correct |
9 |
Correct |
70 ms |
101968 KB |
Output is correct |
10 |
Correct |
240 ms |
104540 KB |
Output is correct |
11 |
Correct |
212 ms |
103064 KB |
Output is correct |
12 |
Correct |
89 ms |
102212 KB |
Output is correct |
13 |
Correct |
174 ms |
104720 KB |
Output is correct |
14 |
Correct |
138 ms |
102740 KB |
Output is correct |
15 |
Correct |
123 ms |
102232 KB |
Output is correct |
16 |
Correct |
114 ms |
102092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
99412 KB |
Output is correct |
2 |
Correct |
53 ms |
99412 KB |
Output is correct |
3 |
Correct |
50 ms |
99412 KB |
Output is correct |
4 |
Correct |
48 ms |
99412 KB |
Output is correct |
5 |
Correct |
45 ms |
99408 KB |
Output is correct |
6 |
Correct |
47 ms |
99476 KB |
Output is correct |
7 |
Correct |
45 ms |
99408 KB |
Output is correct |
8 |
Correct |
51 ms |
99636 KB |
Output is correct |
9 |
Correct |
50 ms |
99376 KB |
Output is correct |
10 |
Correct |
73 ms |
101968 KB |
Output is correct |
11 |
Correct |
107 ms |
102964 KB |
Output is correct |
12 |
Correct |
138 ms |
104276 KB |
Output is correct |
13 |
Correct |
139 ms |
104780 KB |
Output is correct |
14 |
Correct |
115 ms |
103600 KB |
Output is correct |
15 |
Correct |
103 ms |
101972 KB |
Output is correct |
16 |
Correct |
100 ms |
102112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
99412 KB |
Output is correct |
2 |
Correct |
53 ms |
99412 KB |
Output is correct |
3 |
Correct |
50 ms |
99412 KB |
Output is correct |
4 |
Correct |
48 ms |
99412 KB |
Output is correct |
5 |
Correct |
45 ms |
99408 KB |
Output is correct |
6 |
Correct |
47 ms |
99476 KB |
Output is correct |
7 |
Correct |
45 ms |
99408 KB |
Output is correct |
8 |
Correct |
51 ms |
99636 KB |
Output is correct |
9 |
Correct |
50 ms |
99376 KB |
Output is correct |
10 |
Correct |
73 ms |
101968 KB |
Output is correct |
11 |
Correct |
107 ms |
102964 KB |
Output is correct |
12 |
Correct |
138 ms |
104276 KB |
Output is correct |
13 |
Correct |
139 ms |
104780 KB |
Output is correct |
14 |
Correct |
115 ms |
103600 KB |
Output is correct |
15 |
Correct |
103 ms |
101972 KB |
Output is correct |
16 |
Correct |
100 ms |
102112 KB |
Output is correct |
17 |
Correct |
118 ms |
102992 KB |
Output is correct |
18 |
Correct |
45 ms |
99408 KB |
Output is correct |
19 |
Correct |
45 ms |
99400 KB |
Output is correct |
20 |
Correct |
56 ms |
99412 KB |
Output is correct |
21 |
Correct |
47 ms |
99340 KB |
Output is correct |
22 |
Correct |
44 ms |
99260 KB |
Output is correct |
23 |
Correct |
49 ms |
99408 KB |
Output is correct |
24 |
Correct |
51 ms |
99508 KB |
Output is correct |
25 |
Correct |
50 ms |
99616 KB |
Output is correct |
26 |
Correct |
46 ms |
99444 KB |
Output is correct |
27 |
Correct |
76 ms |
102228 KB |
Output is correct |
28 |
Correct |
152 ms |
104520 KB |
Output is correct |
29 |
Correct |
173 ms |
105040 KB |
Output is correct |
30 |
Correct |
129 ms |
103772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
181 ms |
102480 KB |
Output is correct |
2 |
Correct |
47 ms |
99412 KB |
Output is correct |
3 |
Correct |
49 ms |
99416 KB |
Output is correct |
4 |
Correct |
49 ms |
99360 KB |
Output is correct |
5 |
Correct |
47 ms |
99468 KB |
Output is correct |
6 |
Correct |
50 ms |
99356 KB |
Output is correct |
7 |
Correct |
48 ms |
99412 KB |
Output is correct |
8 |
Correct |
76 ms |
102228 KB |
Output is correct |
9 |
Correct |
71 ms |
102072 KB |
Output is correct |
10 |
Correct |
55 ms |
99920 KB |
Output is correct |
11 |
Correct |
173 ms |
102736 KB |
Output is correct |
12 |
Correct |
45 ms |
99408 KB |
Output is correct |
13 |
Correct |
44 ms |
99412 KB |
Output is correct |
14 |
Correct |
43 ms |
99408 KB |
Output is correct |
15 |
Correct |
45 ms |
99408 KB |
Output is correct |
16 |
Correct |
47 ms |
99408 KB |
Output is correct |
17 |
Correct |
42 ms |
99420 KB |
Output is correct |
18 |
Correct |
47 ms |
99544 KB |
Output is correct |
19 |
Correct |
70 ms |
101968 KB |
Output is correct |
20 |
Correct |
240 ms |
104540 KB |
Output is correct |
21 |
Correct |
212 ms |
103064 KB |
Output is correct |
22 |
Correct |
89 ms |
102212 KB |
Output is correct |
23 |
Correct |
174 ms |
104720 KB |
Output is correct |
24 |
Correct |
138 ms |
102740 KB |
Output is correct |
25 |
Correct |
123 ms |
102232 KB |
Output is correct |
26 |
Correct |
114 ms |
102092 KB |
Output is correct |
27 |
Correct |
47 ms |
99412 KB |
Output is correct |
28 |
Correct |
53 ms |
99412 KB |
Output is correct |
29 |
Correct |
50 ms |
99412 KB |
Output is correct |
30 |
Correct |
48 ms |
99412 KB |
Output is correct |
31 |
Correct |
45 ms |
99408 KB |
Output is correct |
32 |
Correct |
47 ms |
99476 KB |
Output is correct |
33 |
Correct |
45 ms |
99408 KB |
Output is correct |
34 |
Correct |
51 ms |
99636 KB |
Output is correct |
35 |
Correct |
50 ms |
99376 KB |
Output is correct |
36 |
Correct |
73 ms |
101968 KB |
Output is correct |
37 |
Correct |
107 ms |
102964 KB |
Output is correct |
38 |
Correct |
138 ms |
104276 KB |
Output is correct |
39 |
Correct |
139 ms |
104780 KB |
Output is correct |
40 |
Correct |
115 ms |
103600 KB |
Output is correct |
41 |
Correct |
103 ms |
101972 KB |
Output is correct |
42 |
Correct |
100 ms |
102112 KB |
Output is correct |
43 |
Correct |
118 ms |
102992 KB |
Output is correct |
44 |
Correct |
45 ms |
99408 KB |
Output is correct |
45 |
Correct |
45 ms |
99400 KB |
Output is correct |
46 |
Correct |
56 ms |
99412 KB |
Output is correct |
47 |
Correct |
47 ms |
99340 KB |
Output is correct |
48 |
Correct |
44 ms |
99260 KB |
Output is correct |
49 |
Correct |
49 ms |
99408 KB |
Output is correct |
50 |
Correct |
51 ms |
99508 KB |
Output is correct |
51 |
Correct |
50 ms |
99616 KB |
Output is correct |
52 |
Correct |
46 ms |
99444 KB |
Output is correct |
53 |
Correct |
76 ms |
102228 KB |
Output is correct |
54 |
Correct |
152 ms |
104520 KB |
Output is correct |
55 |
Correct |
173 ms |
105040 KB |
Output is correct |
56 |
Correct |
129 ms |
103772 KB |
Output is correct |
57 |
Correct |
241 ms |
105784 KB |
Output is correct |
58 |
Correct |
78 ms |
102224 KB |
Output is correct |
59 |
Correct |
174 ms |
103272 KB |
Output is correct |