# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
210702 |
2020-03-18T05:50:03 Z |
super_j6 |
Toll (BOI17_toll) |
C++14 |
|
151 ms |
83580 KB |
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
using namespace std;
#define endl '\n'
#define pi pair<int, int>
const int inf = 0x3f3f3f3f;
const int maxn = 50000, maxk = 5, w = 17;
int n, m, k, q;
int dp[maxk], dp2[maxk];
int st[w][maxn][maxk][maxk];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> k >> n >> m >> q;
n = (n + k - 1) / k;
memset(st, inf, sizeof(st));
for(int i = 0; i < m; i++){
int u, v;
cin >> u >> v >> st[0][u / k][u % k][v % k];
}
for(int i = 1; i < w; i++)
for(int j = 0; j + (1 << i) < n; j++)
for(int f1 = 0; f1 < k; f1++)
for(int f2 = 0; f2 < k; f2++)
for(int f3 = 0; f3 < k; f3++){
st[i][j][f1][f3] = min(st[i][j][f1][f3], st[i - 1][j][f1][f2] + st[i - 1][j + (1 << (i - 1))][f2][f3]);
}
for(int i = 0; i < q; i++){
int u, v;
cin >> u >> v;
memset(dp, inf, sizeof(dp));
dp[u % k] = 0;
u /= k;
for(int j = w - 1; j >= 0; j--){
if(u + (1 << j) <= v / k){
memset(dp2, inf, sizeof(dp2));
for(int f1 = 0; f1 < k; f1++)
for(int f2 = 0; f2 < k; f2++){
dp2[f2] = min(dp2[f2], dp[f1] + st[j][u][f1][f2]);
}
u += (1 << j);
memcpy(dp, dp2, sizeof(dp));
}
}
cout << (dp[v % k] == inf ? -1 : dp[v % k]) << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
83576 KB |
Output is correct |
2 |
Correct |
47 ms |
83576 KB |
Output is correct |
3 |
Correct |
46 ms |
83544 KB |
Output is correct |
4 |
Correct |
46 ms |
83448 KB |
Output is correct |
5 |
Correct |
47 ms |
83448 KB |
Output is correct |
6 |
Correct |
47 ms |
83448 KB |
Output is correct |
7 |
Correct |
47 ms |
83448 KB |
Output is correct |
8 |
Correct |
82 ms |
83576 KB |
Output is correct |
9 |
Correct |
83 ms |
83576 KB |
Output is correct |
10 |
Correct |
63 ms |
83540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
83576 KB |
Output is correct |
2 |
Correct |
47 ms |
83576 KB |
Output is correct |
3 |
Correct |
46 ms |
83448 KB |
Output is correct |
4 |
Correct |
46 ms |
83448 KB |
Output is correct |
5 |
Correct |
45 ms |
83448 KB |
Output is correct |
6 |
Correct |
47 ms |
83448 KB |
Output is correct |
7 |
Correct |
52 ms |
83576 KB |
Output is correct |
8 |
Correct |
50 ms |
83576 KB |
Output is correct |
9 |
Correct |
79 ms |
83576 KB |
Output is correct |
10 |
Correct |
103 ms |
83576 KB |
Output is correct |
11 |
Correct |
88 ms |
83580 KB |
Output is correct |
12 |
Correct |
85 ms |
83560 KB |
Output is correct |
13 |
Correct |
102 ms |
83576 KB |
Output is correct |
14 |
Correct |
79 ms |
83576 KB |
Output is correct |
15 |
Correct |
85 ms |
83580 KB |
Output is correct |
16 |
Correct |
84 ms |
83576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
83452 KB |
Output is correct |
2 |
Correct |
46 ms |
83448 KB |
Output is correct |
3 |
Correct |
46 ms |
83448 KB |
Output is correct |
4 |
Correct |
46 ms |
83448 KB |
Output is correct |
5 |
Correct |
46 ms |
83448 KB |
Output is correct |
6 |
Correct |
48 ms |
83576 KB |
Output is correct |
7 |
Correct |
49 ms |
83448 KB |
Output is correct |
8 |
Correct |
49 ms |
83452 KB |
Output is correct |
9 |
Correct |
49 ms |
83448 KB |
Output is correct |
10 |
Correct |
81 ms |
83448 KB |
Output is correct |
11 |
Correct |
90 ms |
83448 KB |
Output is correct |
12 |
Correct |
108 ms |
83448 KB |
Output is correct |
13 |
Correct |
110 ms |
83448 KB |
Output is correct |
14 |
Correct |
91 ms |
83448 KB |
Output is correct |
15 |
Correct |
83 ms |
83448 KB |
Output is correct |
16 |
Correct |
79 ms |
83580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
83452 KB |
Output is correct |
2 |
Correct |
46 ms |
83448 KB |
Output is correct |
3 |
Correct |
46 ms |
83448 KB |
Output is correct |
4 |
Correct |
46 ms |
83448 KB |
Output is correct |
5 |
Correct |
46 ms |
83448 KB |
Output is correct |
6 |
Correct |
48 ms |
83576 KB |
Output is correct |
7 |
Correct |
49 ms |
83448 KB |
Output is correct |
8 |
Correct |
49 ms |
83452 KB |
Output is correct |
9 |
Correct |
49 ms |
83448 KB |
Output is correct |
10 |
Correct |
81 ms |
83448 KB |
Output is correct |
11 |
Correct |
90 ms |
83448 KB |
Output is correct |
12 |
Correct |
108 ms |
83448 KB |
Output is correct |
13 |
Correct |
110 ms |
83448 KB |
Output is correct |
14 |
Correct |
91 ms |
83448 KB |
Output is correct |
15 |
Correct |
83 ms |
83448 KB |
Output is correct |
16 |
Correct |
79 ms |
83580 KB |
Output is correct |
17 |
Correct |
93 ms |
83576 KB |
Output is correct |
18 |
Correct |
48 ms |
83452 KB |
Output is correct |
19 |
Correct |
47 ms |
83448 KB |
Output is correct |
20 |
Correct |
48 ms |
83448 KB |
Output is correct |
21 |
Correct |
50 ms |
83448 KB |
Output is correct |
22 |
Correct |
47 ms |
83448 KB |
Output is correct |
23 |
Correct |
50 ms |
83448 KB |
Output is correct |
24 |
Correct |
52 ms |
83576 KB |
Output is correct |
25 |
Correct |
54 ms |
83576 KB |
Output is correct |
26 |
Correct |
52 ms |
83576 KB |
Output is correct |
27 |
Correct |
78 ms |
83448 KB |
Output is correct |
28 |
Correct |
103 ms |
83576 KB |
Output is correct |
29 |
Correct |
110 ms |
83576 KB |
Output is correct |
30 |
Correct |
103 ms |
83580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
83576 KB |
Output is correct |
2 |
Correct |
47 ms |
83576 KB |
Output is correct |
3 |
Correct |
46 ms |
83544 KB |
Output is correct |
4 |
Correct |
46 ms |
83448 KB |
Output is correct |
5 |
Correct |
47 ms |
83448 KB |
Output is correct |
6 |
Correct |
47 ms |
83448 KB |
Output is correct |
7 |
Correct |
47 ms |
83448 KB |
Output is correct |
8 |
Correct |
82 ms |
83576 KB |
Output is correct |
9 |
Correct |
83 ms |
83576 KB |
Output is correct |
10 |
Correct |
63 ms |
83540 KB |
Output is correct |
11 |
Correct |
95 ms |
83576 KB |
Output is correct |
12 |
Correct |
47 ms |
83576 KB |
Output is correct |
13 |
Correct |
46 ms |
83448 KB |
Output is correct |
14 |
Correct |
46 ms |
83448 KB |
Output is correct |
15 |
Correct |
45 ms |
83448 KB |
Output is correct |
16 |
Correct |
47 ms |
83448 KB |
Output is correct |
17 |
Correct |
52 ms |
83576 KB |
Output is correct |
18 |
Correct |
50 ms |
83576 KB |
Output is correct |
19 |
Correct |
79 ms |
83576 KB |
Output is correct |
20 |
Correct |
103 ms |
83576 KB |
Output is correct |
21 |
Correct |
88 ms |
83580 KB |
Output is correct |
22 |
Correct |
85 ms |
83560 KB |
Output is correct |
23 |
Correct |
102 ms |
83576 KB |
Output is correct |
24 |
Correct |
79 ms |
83576 KB |
Output is correct |
25 |
Correct |
85 ms |
83580 KB |
Output is correct |
26 |
Correct |
84 ms |
83576 KB |
Output is correct |
27 |
Correct |
45 ms |
83452 KB |
Output is correct |
28 |
Correct |
46 ms |
83448 KB |
Output is correct |
29 |
Correct |
46 ms |
83448 KB |
Output is correct |
30 |
Correct |
46 ms |
83448 KB |
Output is correct |
31 |
Correct |
46 ms |
83448 KB |
Output is correct |
32 |
Correct |
48 ms |
83576 KB |
Output is correct |
33 |
Correct |
49 ms |
83448 KB |
Output is correct |
34 |
Correct |
49 ms |
83452 KB |
Output is correct |
35 |
Correct |
49 ms |
83448 KB |
Output is correct |
36 |
Correct |
81 ms |
83448 KB |
Output is correct |
37 |
Correct |
90 ms |
83448 KB |
Output is correct |
38 |
Correct |
108 ms |
83448 KB |
Output is correct |
39 |
Correct |
110 ms |
83448 KB |
Output is correct |
40 |
Correct |
91 ms |
83448 KB |
Output is correct |
41 |
Correct |
83 ms |
83448 KB |
Output is correct |
42 |
Correct |
79 ms |
83580 KB |
Output is correct |
43 |
Correct |
93 ms |
83576 KB |
Output is correct |
44 |
Correct |
48 ms |
83452 KB |
Output is correct |
45 |
Correct |
47 ms |
83448 KB |
Output is correct |
46 |
Correct |
48 ms |
83448 KB |
Output is correct |
47 |
Correct |
50 ms |
83448 KB |
Output is correct |
48 |
Correct |
47 ms |
83448 KB |
Output is correct |
49 |
Correct |
50 ms |
83448 KB |
Output is correct |
50 |
Correct |
52 ms |
83576 KB |
Output is correct |
51 |
Correct |
54 ms |
83576 KB |
Output is correct |
52 |
Correct |
52 ms |
83576 KB |
Output is correct |
53 |
Correct |
78 ms |
83448 KB |
Output is correct |
54 |
Correct |
103 ms |
83576 KB |
Output is correct |
55 |
Correct |
110 ms |
83576 KB |
Output is correct |
56 |
Correct |
103 ms |
83580 KB |
Output is correct |
57 |
Correct |
151 ms |
83576 KB |
Output is correct |
58 |
Correct |
92 ms |
83576 KB |
Output is correct |
59 |
Correct |
97 ms |
83556 KB |
Output is correct |