# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
847871 |
2023-09-10T16:40:45 Z |
_Avocado_ |
Toll (BOI17_toll) |
C++14 |
|
152 ms |
39844 KB |
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
const int INF = 1e10;
const int LG = 20;
const int MAX_N = 5e4+4;
const int MAX_K = 5;
int up[MAX_N][LG][MAX_K];
int dijkstra(int s, int e, int K, auto&graph){
vector<int>dist(LG*K, -1);
priority_queue<pair<int, int>>pq;
pq.push({0, s});
while(pq.size()){
auto [d, u] = pq.top();
pq.pop();
if(dist[u] != -1) continue;
d = -d;
dist[u] = d;
for(auto [v, w]: graph[u]){
pq.push({-(w+d), v});
}
}
return dist[e];
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
int K, n, m, q; cin>>K>>n>>m>>q;
for(int i = 0; i<MAX_N; ++i){
for(int j = 0; j<LG; ++j){
for(int k = 0; k<MAX_K; ++k) up[i][j][k] = INF;
}
}
for(int i = 0; i<m; ++i){
int a, b, c; cin>>a>>b>>c;
up[a][0][b%K] = c;
}
for(int jumps = 1; jumps<LG; ++jumps){
for(int i = 0; i<n; ++i){
for(int k = 0; k<K; ++k){
for(int middle = 0; middle < K; ++middle){
int mid_node = i/K*K + ((1<<(jumps-1))*K) + middle;
if(mid_node > n) break;
up[i][jumps][k] = min(up[i][jumps][k], up[i][jumps-1][middle] + up[mid_node][jumps-1][k]);
}
}
}
}
for(int i = 0; i<q; ++i){
int a, b; cin>>a>>b;
vector<vector<pair<int, int>>>graph(LG*K);
int cnt = 0;
int group = a/K*K;
int cur_jumps = (b/K) - (a/K);
if(!cur_jumps){
cout<<-1<<'\n';
continue;
}
int start = a%K;
int maxi = 0;
for(int j = LG-1; j>=0; --j){
if(cur_jumps - (1<<j) >= 0){
cur_jumps -= (1<<j);
for(int k1 = 0; k1<K; ++k1){
for(int k2 = 0; k2<K; ++k2){
if(group + k1 > n) break;
int node1 = cnt + k1;
int node2 = cnt + K + k2;
maxi = node2;
graph[node1].push_back({node2, up[group+k1][j][k2]});
}
}
cnt += K;
group += (1<<j)*K;
}
}
/*
for(int j = 0; j<10; ++j){
cout<<"j "<<j<<endl;
for(auto u: graph[j]) cout<<u.first<<" "<<u.second<<endl;
cout<<endl;
}
*/
int end = maxi-K+1+(b%K);
//cout<<"end "<<end<<endl;
int ans = dijkstra(start, end, K, graph);
if(ans >= INF) cout<<-1<<'\n';
else cout<<ans<<'\n';
}
//cout<<'\n';
}
Compilation message
toll.cpp:12:35: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
12 | int dijkstra(int s, int e, int K, auto&graph){
| ^~~~
toll.cpp: In function 'int64_t dijkstra(int64_t, int64_t, int64_t, auto:1&)':
toll.cpp:19:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
19 | auto [d, u] = pq.top();
| ^
toll.cpp:27:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
27 | for(auto [v, w]: graph[u]){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
39512 KB |
Output is correct |
2 |
Correct |
6 ms |
39512 KB |
Output is correct |
3 |
Correct |
7 ms |
39772 KB |
Output is correct |
4 |
Correct |
6 ms |
39372 KB |
Output is correct |
5 |
Correct |
7 ms |
39512 KB |
Output is correct |
6 |
Correct |
8 ms |
39512 KB |
Output is correct |
7 |
Correct |
7 ms |
39516 KB |
Output is correct |
8 |
Correct |
36 ms |
39772 KB |
Output is correct |
9 |
Correct |
36 ms |
39516 KB |
Output is correct |
10 |
Correct |
24 ms |
39516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
39512 KB |
Output is correct |
2 |
Correct |
6 ms |
39512 KB |
Output is correct |
3 |
Correct |
6 ms |
39516 KB |
Output is correct |
4 |
Correct |
6 ms |
39516 KB |
Output is correct |
5 |
Correct |
6 ms |
39608 KB |
Output is correct |
6 |
Correct |
7 ms |
39516 KB |
Output is correct |
7 |
Correct |
12 ms |
39516 KB |
Output is correct |
8 |
Correct |
18 ms |
39516 KB |
Output is correct |
9 |
Correct |
32 ms |
39516 KB |
Output is correct |
10 |
Correct |
101 ms |
39512 KB |
Output is correct |
11 |
Correct |
68 ms |
39584 KB |
Output is correct |
12 |
Correct |
92 ms |
39516 KB |
Output is correct |
13 |
Correct |
85 ms |
39596 KB |
Output is correct |
14 |
Correct |
48 ms |
39512 KB |
Output is correct |
15 |
Correct |
72 ms |
39712 KB |
Output is correct |
16 |
Correct |
78 ms |
39516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
39516 KB |
Output is correct |
2 |
Correct |
6 ms |
39516 KB |
Output is correct |
3 |
Correct |
6 ms |
39516 KB |
Output is correct |
4 |
Correct |
6 ms |
39516 KB |
Output is correct |
5 |
Correct |
6 ms |
39516 KB |
Output is correct |
6 |
Correct |
7 ms |
39516 KB |
Output is correct |
7 |
Correct |
7 ms |
39596 KB |
Output is correct |
8 |
Correct |
8 ms |
39516 KB |
Output is correct |
9 |
Correct |
8 ms |
39516 KB |
Output is correct |
10 |
Correct |
25 ms |
39600 KB |
Output is correct |
11 |
Correct |
47 ms |
39516 KB |
Output is correct |
12 |
Correct |
56 ms |
39516 KB |
Output is correct |
13 |
Correct |
58 ms |
39516 KB |
Output is correct |
14 |
Correct |
51 ms |
39512 KB |
Output is correct |
15 |
Correct |
40 ms |
39512 KB |
Output is correct |
16 |
Correct |
42 ms |
39844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
39516 KB |
Output is correct |
2 |
Correct |
6 ms |
39516 KB |
Output is correct |
3 |
Correct |
6 ms |
39516 KB |
Output is correct |
4 |
Correct |
6 ms |
39516 KB |
Output is correct |
5 |
Correct |
6 ms |
39516 KB |
Output is correct |
6 |
Correct |
7 ms |
39516 KB |
Output is correct |
7 |
Correct |
7 ms |
39596 KB |
Output is correct |
8 |
Correct |
8 ms |
39516 KB |
Output is correct |
9 |
Correct |
8 ms |
39516 KB |
Output is correct |
10 |
Correct |
25 ms |
39600 KB |
Output is correct |
11 |
Correct |
47 ms |
39516 KB |
Output is correct |
12 |
Correct |
56 ms |
39516 KB |
Output is correct |
13 |
Correct |
58 ms |
39516 KB |
Output is correct |
14 |
Correct |
51 ms |
39512 KB |
Output is correct |
15 |
Correct |
40 ms |
39512 KB |
Output is correct |
16 |
Correct |
42 ms |
39844 KB |
Output is correct |
17 |
Correct |
53 ms |
39516 KB |
Output is correct |
18 |
Correct |
6 ms |
39512 KB |
Output is correct |
19 |
Correct |
6 ms |
39368 KB |
Output is correct |
20 |
Correct |
6 ms |
39516 KB |
Output is correct |
21 |
Correct |
6 ms |
39516 KB |
Output is correct |
22 |
Correct |
6 ms |
39588 KB |
Output is correct |
23 |
Correct |
9 ms |
39516 KB |
Output is correct |
24 |
Correct |
10 ms |
39600 KB |
Output is correct |
25 |
Correct |
23 ms |
39516 KB |
Output is correct |
26 |
Correct |
18 ms |
39624 KB |
Output is correct |
27 |
Correct |
28 ms |
39512 KB |
Output is correct |
28 |
Correct |
92 ms |
39572 KB |
Output is correct |
29 |
Correct |
75 ms |
39572 KB |
Output is correct |
30 |
Correct |
68 ms |
39592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
39512 KB |
Output is correct |
2 |
Correct |
6 ms |
39512 KB |
Output is correct |
3 |
Correct |
7 ms |
39772 KB |
Output is correct |
4 |
Correct |
6 ms |
39372 KB |
Output is correct |
5 |
Correct |
7 ms |
39512 KB |
Output is correct |
6 |
Correct |
8 ms |
39512 KB |
Output is correct |
7 |
Correct |
7 ms |
39516 KB |
Output is correct |
8 |
Correct |
36 ms |
39772 KB |
Output is correct |
9 |
Correct |
36 ms |
39516 KB |
Output is correct |
10 |
Correct |
24 ms |
39516 KB |
Output is correct |
11 |
Correct |
63 ms |
39512 KB |
Output is correct |
12 |
Correct |
6 ms |
39512 KB |
Output is correct |
13 |
Correct |
6 ms |
39516 KB |
Output is correct |
14 |
Correct |
6 ms |
39516 KB |
Output is correct |
15 |
Correct |
6 ms |
39608 KB |
Output is correct |
16 |
Correct |
7 ms |
39516 KB |
Output is correct |
17 |
Correct |
12 ms |
39516 KB |
Output is correct |
18 |
Correct |
18 ms |
39516 KB |
Output is correct |
19 |
Correct |
32 ms |
39516 KB |
Output is correct |
20 |
Correct |
101 ms |
39512 KB |
Output is correct |
21 |
Correct |
68 ms |
39584 KB |
Output is correct |
22 |
Correct |
92 ms |
39516 KB |
Output is correct |
23 |
Correct |
85 ms |
39596 KB |
Output is correct |
24 |
Correct |
48 ms |
39512 KB |
Output is correct |
25 |
Correct |
72 ms |
39712 KB |
Output is correct |
26 |
Correct |
78 ms |
39516 KB |
Output is correct |
27 |
Correct |
6 ms |
39516 KB |
Output is correct |
28 |
Correct |
6 ms |
39516 KB |
Output is correct |
29 |
Correct |
6 ms |
39516 KB |
Output is correct |
30 |
Correct |
6 ms |
39516 KB |
Output is correct |
31 |
Correct |
6 ms |
39516 KB |
Output is correct |
32 |
Correct |
7 ms |
39516 KB |
Output is correct |
33 |
Correct |
7 ms |
39596 KB |
Output is correct |
34 |
Correct |
8 ms |
39516 KB |
Output is correct |
35 |
Correct |
8 ms |
39516 KB |
Output is correct |
36 |
Correct |
25 ms |
39600 KB |
Output is correct |
37 |
Correct |
47 ms |
39516 KB |
Output is correct |
38 |
Correct |
56 ms |
39516 KB |
Output is correct |
39 |
Correct |
58 ms |
39516 KB |
Output is correct |
40 |
Correct |
51 ms |
39512 KB |
Output is correct |
41 |
Correct |
40 ms |
39512 KB |
Output is correct |
42 |
Correct |
42 ms |
39844 KB |
Output is correct |
43 |
Correct |
53 ms |
39516 KB |
Output is correct |
44 |
Correct |
6 ms |
39512 KB |
Output is correct |
45 |
Correct |
6 ms |
39368 KB |
Output is correct |
46 |
Correct |
6 ms |
39516 KB |
Output is correct |
47 |
Correct |
6 ms |
39516 KB |
Output is correct |
48 |
Correct |
6 ms |
39588 KB |
Output is correct |
49 |
Correct |
9 ms |
39516 KB |
Output is correct |
50 |
Correct |
10 ms |
39600 KB |
Output is correct |
51 |
Correct |
23 ms |
39516 KB |
Output is correct |
52 |
Correct |
18 ms |
39624 KB |
Output is correct |
53 |
Correct |
28 ms |
39512 KB |
Output is correct |
54 |
Correct |
92 ms |
39572 KB |
Output is correct |
55 |
Correct |
75 ms |
39572 KB |
Output is correct |
56 |
Correct |
68 ms |
39592 KB |
Output is correct |
57 |
Correct |
152 ms |
39576 KB |
Output is correct |
58 |
Correct |
34 ms |
39608 KB |
Output is correct |
59 |
Correct |
67 ms |
39588 KB |
Output is correct |