# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
298035 |
2020-09-12T10:02:59 Z |
miss_robot |
Toll (BOI17_toll) |
C++14 |
|
264 ms |
73596 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define int long long
using namespace std;
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
int k, n, m, o, L = 16, INF = numeric_limits<int>::max()/8;
cin >> k >> n >> m >> o;
vector< vector< vector< vector<int> > > > g(L, vector< vector< vector<int> > >((n+k-1)/k, vector< vector<int> >(k, vector<int>(k, INF))));
while(m--){
int a, b, t;
cin >> a >> b >> t;
g[0][a/k][a%k][b%k] = t;
}
for(int i = 1; i < L; i++)
for(int j = 0; j < (n+k-1)/k-(1<<i); j++)
for(int u = 0; u < k; u++)
for(int v = 0; v < k; v++)
for(int w = 0; w < k; w++)
g[i][j][u][v] = min(g[i][j][u][v], g[i-1][j][u][w]+g[i-1][j+(1<<(i-1))][w][v]);
while(o--){
int a, b, pos;
cin >> a >> b;
if(a/k == b/k){
cout << "-1\n";
continue;
}
vector<int> dis(k, INF);
dis[a%k] = 0;
pos = a/k;
for(int i = L-1; i >= 0; i--){
if(pos + (1<<i) > b/k) continue;
vector<int> newdis(k, INF);
for(int u = 0; u < k; u++)
for(int v = 0; v < k; v++)
newdis[v] = min(newdis[v], dis[u]+g[i][pos][u][v]);
dis = newdis;
pos += (1<<i);
}
cout << (dis[b%k]==INF?-1:dis[b%k]) << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
191 ms |
73556 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
1792 KB |
Output is correct |
6 |
Correct |
4 ms |
1792 KB |
Output is correct |
7 |
Correct |
4 ms |
1792 KB |
Output is correct |
8 |
Correct |
186 ms |
73596 KB |
Output is correct |
9 |
Correct |
200 ms |
73592 KB |
Output is correct |
10 |
Correct |
166 ms |
73592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
222 ms |
64676 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
10 ms |
1920 KB |
Output is correct |
8 |
Correct |
11 ms |
1792 KB |
Output is correct |
9 |
Correct |
170 ms |
73592 KB |
Output is correct |
10 |
Correct |
210 ms |
57712 KB |
Output is correct |
11 |
Correct |
177 ms |
64812 KB |
Output is correct |
12 |
Correct |
164 ms |
56688 KB |
Output is correct |
13 |
Correct |
156 ms |
41916 KB |
Output is correct |
14 |
Correct |
103 ms |
34828 KB |
Output is correct |
15 |
Correct |
114 ms |
40676 KB |
Output is correct |
16 |
Correct |
114 ms |
40680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
1808 KB |
Output is correct |
7 |
Correct |
3 ms |
1664 KB |
Output is correct |
8 |
Correct |
4 ms |
1664 KB |
Output is correct |
9 |
Correct |
4 ms |
1792 KB |
Output is correct |
10 |
Correct |
155 ms |
73592 KB |
Output is correct |
11 |
Correct |
150 ms |
64684 KB |
Output is correct |
12 |
Correct |
169 ms |
57792 KB |
Output is correct |
13 |
Correct |
162 ms |
57840 KB |
Output is correct |
14 |
Correct |
162 ms |
57324 KB |
Output is correct |
15 |
Correct |
118 ms |
40552 KB |
Output is correct |
16 |
Correct |
111 ms |
40552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
1808 KB |
Output is correct |
7 |
Correct |
3 ms |
1664 KB |
Output is correct |
8 |
Correct |
4 ms |
1664 KB |
Output is correct |
9 |
Correct |
4 ms |
1792 KB |
Output is correct |
10 |
Correct |
155 ms |
73592 KB |
Output is correct |
11 |
Correct |
150 ms |
64684 KB |
Output is correct |
12 |
Correct |
169 ms |
57792 KB |
Output is correct |
13 |
Correct |
162 ms |
57840 KB |
Output is correct |
14 |
Correct |
162 ms |
57324 KB |
Output is correct |
15 |
Correct |
118 ms |
40552 KB |
Output is correct |
16 |
Correct |
111 ms |
40552 KB |
Output is correct |
17 |
Correct |
162 ms |
64640 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
6 ms |
1920 KB |
Output is correct |
24 |
Correct |
8 ms |
1664 KB |
Output is correct |
25 |
Correct |
7 ms |
1792 KB |
Output is correct |
26 |
Correct |
7 ms |
1792 KB |
Output is correct |
27 |
Correct |
174 ms |
73592 KB |
Output is correct |
28 |
Correct |
162 ms |
57712 KB |
Output is correct |
29 |
Correct |
188 ms |
57888 KB |
Output is correct |
30 |
Correct |
156 ms |
57328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
191 ms |
73556 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
1792 KB |
Output is correct |
6 |
Correct |
4 ms |
1792 KB |
Output is correct |
7 |
Correct |
4 ms |
1792 KB |
Output is correct |
8 |
Correct |
186 ms |
73596 KB |
Output is correct |
9 |
Correct |
200 ms |
73592 KB |
Output is correct |
10 |
Correct |
166 ms |
73592 KB |
Output is correct |
11 |
Correct |
222 ms |
64676 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
10 ms |
1920 KB |
Output is correct |
18 |
Correct |
11 ms |
1792 KB |
Output is correct |
19 |
Correct |
170 ms |
73592 KB |
Output is correct |
20 |
Correct |
210 ms |
57712 KB |
Output is correct |
21 |
Correct |
177 ms |
64812 KB |
Output is correct |
22 |
Correct |
164 ms |
56688 KB |
Output is correct |
23 |
Correct |
156 ms |
41916 KB |
Output is correct |
24 |
Correct |
103 ms |
34828 KB |
Output is correct |
25 |
Correct |
114 ms |
40676 KB |
Output is correct |
26 |
Correct |
114 ms |
40680 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
3 ms |
1808 KB |
Output is correct |
33 |
Correct |
3 ms |
1664 KB |
Output is correct |
34 |
Correct |
4 ms |
1664 KB |
Output is correct |
35 |
Correct |
4 ms |
1792 KB |
Output is correct |
36 |
Correct |
155 ms |
73592 KB |
Output is correct |
37 |
Correct |
150 ms |
64684 KB |
Output is correct |
38 |
Correct |
169 ms |
57792 KB |
Output is correct |
39 |
Correct |
162 ms |
57840 KB |
Output is correct |
40 |
Correct |
162 ms |
57324 KB |
Output is correct |
41 |
Correct |
118 ms |
40552 KB |
Output is correct |
42 |
Correct |
111 ms |
40552 KB |
Output is correct |
43 |
Correct |
162 ms |
64640 KB |
Output is correct |
44 |
Correct |
1 ms |
384 KB |
Output is correct |
45 |
Correct |
1 ms |
384 KB |
Output is correct |
46 |
Correct |
1 ms |
384 KB |
Output is correct |
47 |
Correct |
1 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
384 KB |
Output is correct |
49 |
Correct |
6 ms |
1920 KB |
Output is correct |
50 |
Correct |
8 ms |
1664 KB |
Output is correct |
51 |
Correct |
7 ms |
1792 KB |
Output is correct |
52 |
Correct |
7 ms |
1792 KB |
Output is correct |
53 |
Correct |
174 ms |
73592 KB |
Output is correct |
54 |
Correct |
162 ms |
57712 KB |
Output is correct |
55 |
Correct |
188 ms |
57888 KB |
Output is correct |
56 |
Correct |
156 ms |
57328 KB |
Output is correct |
57 |
Correct |
264 ms |
71632 KB |
Output is correct |
58 |
Correct |
191 ms |
73592 KB |
Output is correct |
59 |
Correct |
182 ms |
64812 KB |
Output is correct |