# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
186904 |
2020-01-12T11:34:35 Z |
AlexPop28 |
Toll (BOI17_toll) |
C++11 |
|
306 ms |
49896 KB |
#include <bits/stdc++.h>
#define dbg() cerr <<
#define name(x) (#x) << ": " << (x) << ' ' <<
// a doua zi dupa 11 ore de somn merge mai bine garantez eu
// ah.. sau poate ca nu.. sau?
using namespace std;
const int INF = (int)1e9 + 5;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int k, n, m, q; cin >> k >> n >> m >> q;
int groups = (n + k - 1) / k;
int log_groups = 32 - __builtin_clz(groups);
vector<vector<vector<int>>> dist(log_groups,
vector<vector<int>>(n,
vector<int>(k, INF)));
vector<vector<pair<int, int>>> adj(n);
for (int i = 0; i < m; ++i) {
int a, b, c; cin >> a >> b >> c;
adj[a].emplace_back(b, c);
adj[b].emplace_back(a, c);
dist[0][a][b % k] = c;
}
for (int p = 1; p < log_groups; ++p) {
for (int from = 0; from / k + (1 << p) <= (n - 1) / k; ++from) {
for (int to = 0; to < k; ++to) {
int gr = from / k + (1 << (p - 1));
int lst = min((gr + 1) * k, n);
for (int x = gr * k, r = 0; x < lst; ++x, ++r) {
dist[p][from][to] = min(dist[p][from][to],
dist[p - 1][from][r] + dist[p - 1][x][to]);
}
}
}
}
while (q--) {
int a, b; cin >> a >> b;
//dbg() name(a) name(b) endl;
vector<int> d(k, INF);
d[a % k] = 0;
a = a / k;
int len = b / k - a;
for (int bit = 0; (1 << bit) <= len; ++bit) {
if (((1 << bit) & len) == 0) continue;
vector<int> nd(k, INF);
//dbg() name(bit) endl;
for (int from = a * k; from < (a + 1) * k; ++from) {
for (int x = 0; x < k; ++x) {
nd[x] = min(nd[x], d[from - a * k] + dist[bit][from][x]);
}
}
a += 1 << bit;
d = move(nd);
}
int ans = d[b % k];
if (ans == INF) ans = -1;
cout << ans << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
48004 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
4 ms |
888 KB |
Output is correct |
6 |
Correct |
4 ms |
1016 KB |
Output is correct |
7 |
Correct |
6 ms |
1016 KB |
Output is correct |
8 |
Correct |
209 ms |
47976 KB |
Output is correct |
9 |
Correct |
155 ms |
47840 KB |
Output is correct |
10 |
Correct |
115 ms |
46968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
198 ms |
47072 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
392 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
10 ms |
1016 KB |
Output is correct |
8 |
Correct |
11 ms |
1188 KB |
Output is correct |
9 |
Correct |
172 ms |
47816 KB |
Output is correct |
10 |
Correct |
239 ms |
49224 KB |
Output is correct |
11 |
Correct |
200 ms |
47088 KB |
Output is correct |
12 |
Correct |
173 ms |
46432 KB |
Output is correct |
13 |
Correct |
193 ms |
29808 KB |
Output is correct |
14 |
Correct |
134 ms |
28344 KB |
Output is correct |
15 |
Correct |
139 ms |
26004 KB |
Output is correct |
16 |
Correct |
135 ms |
26020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
888 KB |
Output is correct |
7 |
Correct |
4 ms |
892 KB |
Output is correct |
8 |
Correct |
6 ms |
1016 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
152 ms |
47840 KB |
Output is correct |
11 |
Correct |
178 ms |
46888 KB |
Output is correct |
12 |
Correct |
236 ms |
49088 KB |
Output is correct |
13 |
Correct |
238 ms |
49584 KB |
Output is correct |
14 |
Correct |
210 ms |
48204 KB |
Output is correct |
15 |
Correct |
133 ms |
25912 KB |
Output is correct |
16 |
Correct |
134 ms |
25884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
888 KB |
Output is correct |
7 |
Correct |
4 ms |
892 KB |
Output is correct |
8 |
Correct |
6 ms |
1016 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
152 ms |
47840 KB |
Output is correct |
11 |
Correct |
178 ms |
46888 KB |
Output is correct |
12 |
Correct |
236 ms |
49088 KB |
Output is correct |
13 |
Correct |
238 ms |
49584 KB |
Output is correct |
14 |
Correct |
210 ms |
48204 KB |
Output is correct |
15 |
Correct |
133 ms |
25912 KB |
Output is correct |
16 |
Correct |
134 ms |
25884 KB |
Output is correct |
17 |
Correct |
231 ms |
46904 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
380 KB |
Output is correct |
23 |
Correct |
6 ms |
888 KB |
Output is correct |
24 |
Correct |
6 ms |
1016 KB |
Output is correct |
25 |
Correct |
8 ms |
1016 KB |
Output is correct |
26 |
Correct |
7 ms |
1016 KB |
Output is correct |
27 |
Correct |
146 ms |
47876 KB |
Output is correct |
28 |
Correct |
233 ms |
49124 KB |
Output is correct |
29 |
Correct |
254 ms |
49896 KB |
Output is correct |
30 |
Correct |
219 ms |
48268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
48004 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
4 ms |
888 KB |
Output is correct |
6 |
Correct |
4 ms |
1016 KB |
Output is correct |
7 |
Correct |
6 ms |
1016 KB |
Output is correct |
8 |
Correct |
209 ms |
47976 KB |
Output is correct |
9 |
Correct |
155 ms |
47840 KB |
Output is correct |
10 |
Correct |
115 ms |
46968 KB |
Output is correct |
11 |
Correct |
198 ms |
47072 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
392 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
10 ms |
1016 KB |
Output is correct |
18 |
Correct |
11 ms |
1188 KB |
Output is correct |
19 |
Correct |
172 ms |
47816 KB |
Output is correct |
20 |
Correct |
239 ms |
49224 KB |
Output is correct |
21 |
Correct |
200 ms |
47088 KB |
Output is correct |
22 |
Correct |
173 ms |
46432 KB |
Output is correct |
23 |
Correct |
193 ms |
29808 KB |
Output is correct |
24 |
Correct |
134 ms |
28344 KB |
Output is correct |
25 |
Correct |
139 ms |
26004 KB |
Output is correct |
26 |
Correct |
135 ms |
26020 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
248 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
4 ms |
888 KB |
Output is correct |
33 |
Correct |
4 ms |
892 KB |
Output is correct |
34 |
Correct |
6 ms |
1016 KB |
Output is correct |
35 |
Correct |
5 ms |
888 KB |
Output is correct |
36 |
Correct |
152 ms |
47840 KB |
Output is correct |
37 |
Correct |
178 ms |
46888 KB |
Output is correct |
38 |
Correct |
236 ms |
49088 KB |
Output is correct |
39 |
Correct |
238 ms |
49584 KB |
Output is correct |
40 |
Correct |
210 ms |
48204 KB |
Output is correct |
41 |
Correct |
133 ms |
25912 KB |
Output is correct |
42 |
Correct |
134 ms |
25884 KB |
Output is correct |
43 |
Correct |
231 ms |
46904 KB |
Output is correct |
44 |
Correct |
2 ms |
376 KB |
Output is correct |
45 |
Correct |
2 ms |
376 KB |
Output is correct |
46 |
Correct |
2 ms |
376 KB |
Output is correct |
47 |
Correct |
2 ms |
376 KB |
Output is correct |
48 |
Correct |
2 ms |
380 KB |
Output is correct |
49 |
Correct |
6 ms |
888 KB |
Output is correct |
50 |
Correct |
6 ms |
1016 KB |
Output is correct |
51 |
Correct |
8 ms |
1016 KB |
Output is correct |
52 |
Correct |
7 ms |
1016 KB |
Output is correct |
53 |
Correct |
146 ms |
47876 KB |
Output is correct |
54 |
Correct |
233 ms |
49124 KB |
Output is correct |
55 |
Correct |
254 ms |
49896 KB |
Output is correct |
56 |
Correct |
219 ms |
48268 KB |
Output is correct |
57 |
Correct |
306 ms |
47716 KB |
Output is correct |
58 |
Correct |
163 ms |
47880 KB |
Output is correct |
59 |
Correct |
206 ms |
47216 KB |
Output is correct |