# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
450412 |
2021-08-02T19:51:03 Z |
snoop |
Toll (BOI17_toll) |
C++14 |
|
206 ms |
22792 KB |
#include<bits/stdc++.h>
#include<math.h>
#define f first
#define s second
#define int long long
using namespace std;
const int N = 5e4 + 5, oo = 1e18;
int t, dist[N][5][5], d[N][5][5], n, k, m, q, ans[N];
vector<int> cur[N];
pair<int, int> p[N];
void solve(int l, int r, vector<int> v) {
if (l == r) return;
int mid = (l + r) / 2;
vector<int> x, y;
for (int i = l; i <= r; i++) cur[i].clear();
for (int i = 0; i < v.size(); i++) {
int ind = v[i];
if (p[ind].s / k <= mid) x.push_back(v[i]);
else if (p[ind].f / k >= mid + 1) y.push_back(v[i]);
else cur[p[ind].s / k].push_back(v[i]);
}
for (int j = 0; j < k; j++) {
for (int x = 0; x < k; x++) {
d[mid + 1][j][x] = 0;
}
}
for (int i = mid; i >= l; i--) {
for (int from = 0; from < k; from++) {
for (int to = 0; to < k; to++) {
d[i][from][to] = oo;
for (int j = 0; j < k; j++) {
if(i == mid) d[i][from][to] = dist[i][from][to];
else d[i][from][to] = min(d[i][from][to], d[i + 1][j][to] + dist[i][from][j]);
}
}
}
}
for (int i = mid + 2; i <= r; i++) {
for (int from = 0; from < k; from++) {
for (int to = 0; to < k; to++) {
d[i][from][to] = oo;
for (int j = 0; j < k; j++) {
if(i == mid+2) d[i][from][to] = dist[i-1][to][from];
else d[i][from][to] = min(d[i][from][to], d[i - 1][j][to] + dist[i-1][j][from]);
}
}
}
}
for (int i = mid + 1; i <= r; i++) {
for (int j = 0; j < cur[i].size(); j++) {
int ind = cur[i][j];
ans[ind] = oo;
for (int x = 0; x < k; x++) {
ans[ind] = min(ans[ind], d[p[ind].f / k][p[ind].f % k][x]
+ d[i][p[ind].s % k][x] );
}
if (i == mid + 1) ans[ind] = d[p[ind].f / k][p[ind].f % k][p[ind].s % k];
}
}
solve(l, mid, x);
solve(mid + 1, r, y);
}
signed main() {
cin >> k >> n >> m >> q;
for (int i = 0; i <= n / k; i++) {
for (int j = 0; j < k; j++) {
for (int x = 0; x < k; x++) dist[i][j][x] = oo;
}
}
for (int i = 1; i <= m; i++) {
int u, v, w;
cin >> u >> v >> w;
dist[u / k][u % k][v % k] = w;
}
vector<int> all;
for (int i = 1; i <= q; i++) {
cin >> p[i].f >> p[i].s;
ans[i] = oo;
if (p[i].s <= p[i].f) ans[i] = -1;
else all.push_back(i);
}
solve(0, n / k, all);
for (int i = 1; i <= q; i++) {
if (ans[i] == oo) cout << -1;
else cout << ans[i];
cout << "\n";
}
}
Compilation message
toll.cpp: In function 'void solve(long long int, long long int, std::vector<long long int>)':
toll.cpp:16:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
toll.cpp:53:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int j = 0; j < cur[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
21880 KB |
Output is correct |
2 |
Correct |
1 ms |
1484 KB |
Output is correct |
3 |
Correct |
1 ms |
1484 KB |
Output is correct |
4 |
Correct |
1 ms |
1484 KB |
Output is correct |
5 |
Correct |
3 ms |
1884 KB |
Output is correct |
6 |
Correct |
3 ms |
1868 KB |
Output is correct |
7 |
Correct |
3 ms |
1868 KB |
Output is correct |
8 |
Correct |
78 ms |
22644 KB |
Output is correct |
9 |
Correct |
72 ms |
22636 KB |
Output is correct |
10 |
Correct |
27 ms |
21900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
12140 KB |
Output is correct |
2 |
Correct |
1 ms |
1484 KB |
Output is correct |
3 |
Correct |
1 ms |
1484 KB |
Output is correct |
4 |
Correct |
1 ms |
1484 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
1 ms |
1484 KB |
Output is correct |
7 |
Correct |
9 ms |
2636 KB |
Output is correct |
8 |
Correct |
10 ms |
2508 KB |
Output is correct |
9 |
Correct |
73 ms |
22792 KB |
Output is correct |
10 |
Correct |
150 ms |
11076 KB |
Output is correct |
11 |
Correct |
112 ms |
13764 KB |
Output is correct |
12 |
Correct |
90 ms |
10100 KB |
Output is correct |
13 |
Correct |
154 ms |
6568 KB |
Output is correct |
14 |
Correct |
90 ms |
7000 KB |
Output is correct |
15 |
Correct |
87 ms |
5208 KB |
Output is correct |
16 |
Correct |
88 ms |
5192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1484 KB |
Output is correct |
2 |
Correct |
1 ms |
1484 KB |
Output is correct |
3 |
Correct |
1 ms |
1484 KB |
Output is correct |
4 |
Correct |
1 ms |
1484 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
2 ms |
1996 KB |
Output is correct |
7 |
Correct |
3 ms |
1612 KB |
Output is correct |
8 |
Correct |
5 ms |
1612 KB |
Output is correct |
9 |
Correct |
4 ms |
1612 KB |
Output is correct |
10 |
Correct |
65 ms |
21748 KB |
Output is correct |
11 |
Correct |
104 ms |
12748 KB |
Output is correct |
12 |
Correct |
136 ms |
10104 KB |
Output is correct |
13 |
Correct |
152 ms |
10308 KB |
Output is correct |
14 |
Correct |
135 ms |
9708 KB |
Output is correct |
15 |
Correct |
85 ms |
4932 KB |
Output is correct |
16 |
Correct |
84 ms |
4980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1484 KB |
Output is correct |
2 |
Correct |
1 ms |
1484 KB |
Output is correct |
3 |
Correct |
1 ms |
1484 KB |
Output is correct |
4 |
Correct |
1 ms |
1484 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
2 ms |
1996 KB |
Output is correct |
7 |
Correct |
3 ms |
1612 KB |
Output is correct |
8 |
Correct |
5 ms |
1612 KB |
Output is correct |
9 |
Correct |
4 ms |
1612 KB |
Output is correct |
10 |
Correct |
65 ms |
21748 KB |
Output is correct |
11 |
Correct |
104 ms |
12748 KB |
Output is correct |
12 |
Correct |
136 ms |
10104 KB |
Output is correct |
13 |
Correct |
152 ms |
10308 KB |
Output is correct |
14 |
Correct |
135 ms |
9708 KB |
Output is correct |
15 |
Correct |
85 ms |
4932 KB |
Output is correct |
16 |
Correct |
84 ms |
4980 KB |
Output is correct |
17 |
Correct |
101 ms |
13008 KB |
Output is correct |
18 |
Correct |
1 ms |
1484 KB |
Output is correct |
19 |
Correct |
1 ms |
1484 KB |
Output is correct |
20 |
Correct |
1 ms |
1484 KB |
Output is correct |
21 |
Correct |
2 ms |
1488 KB |
Output is correct |
22 |
Correct |
1 ms |
1484 KB |
Output is correct |
23 |
Correct |
4 ms |
2124 KB |
Output is correct |
24 |
Correct |
5 ms |
1868 KB |
Output is correct |
25 |
Correct |
7 ms |
1740 KB |
Output is correct |
26 |
Correct |
6 ms |
1748 KB |
Output is correct |
27 |
Correct |
67 ms |
22128 KB |
Output is correct |
28 |
Correct |
139 ms |
10352 KB |
Output is correct |
29 |
Correct |
154 ms |
10612 KB |
Output is correct |
30 |
Correct |
124 ms |
10112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
21880 KB |
Output is correct |
2 |
Correct |
1 ms |
1484 KB |
Output is correct |
3 |
Correct |
1 ms |
1484 KB |
Output is correct |
4 |
Correct |
1 ms |
1484 KB |
Output is correct |
5 |
Correct |
3 ms |
1884 KB |
Output is correct |
6 |
Correct |
3 ms |
1868 KB |
Output is correct |
7 |
Correct |
3 ms |
1868 KB |
Output is correct |
8 |
Correct |
78 ms |
22644 KB |
Output is correct |
9 |
Correct |
72 ms |
22636 KB |
Output is correct |
10 |
Correct |
27 ms |
21900 KB |
Output is correct |
11 |
Correct |
106 ms |
12140 KB |
Output is correct |
12 |
Correct |
1 ms |
1484 KB |
Output is correct |
13 |
Correct |
1 ms |
1484 KB |
Output is correct |
14 |
Correct |
1 ms |
1484 KB |
Output is correct |
15 |
Correct |
1 ms |
1484 KB |
Output is correct |
16 |
Correct |
1 ms |
1484 KB |
Output is correct |
17 |
Correct |
9 ms |
2636 KB |
Output is correct |
18 |
Correct |
10 ms |
2508 KB |
Output is correct |
19 |
Correct |
73 ms |
22792 KB |
Output is correct |
20 |
Correct |
150 ms |
11076 KB |
Output is correct |
21 |
Correct |
112 ms |
13764 KB |
Output is correct |
22 |
Correct |
90 ms |
10100 KB |
Output is correct |
23 |
Correct |
154 ms |
6568 KB |
Output is correct |
24 |
Correct |
90 ms |
7000 KB |
Output is correct |
25 |
Correct |
87 ms |
5208 KB |
Output is correct |
26 |
Correct |
88 ms |
5192 KB |
Output is correct |
27 |
Correct |
1 ms |
1484 KB |
Output is correct |
28 |
Correct |
1 ms |
1484 KB |
Output is correct |
29 |
Correct |
1 ms |
1484 KB |
Output is correct |
30 |
Correct |
1 ms |
1484 KB |
Output is correct |
31 |
Correct |
1 ms |
1484 KB |
Output is correct |
32 |
Correct |
2 ms |
1996 KB |
Output is correct |
33 |
Correct |
3 ms |
1612 KB |
Output is correct |
34 |
Correct |
5 ms |
1612 KB |
Output is correct |
35 |
Correct |
4 ms |
1612 KB |
Output is correct |
36 |
Correct |
65 ms |
21748 KB |
Output is correct |
37 |
Correct |
104 ms |
12748 KB |
Output is correct |
38 |
Correct |
136 ms |
10104 KB |
Output is correct |
39 |
Correct |
152 ms |
10308 KB |
Output is correct |
40 |
Correct |
135 ms |
9708 KB |
Output is correct |
41 |
Correct |
85 ms |
4932 KB |
Output is correct |
42 |
Correct |
84 ms |
4980 KB |
Output is correct |
43 |
Correct |
101 ms |
13008 KB |
Output is correct |
44 |
Correct |
1 ms |
1484 KB |
Output is correct |
45 |
Correct |
1 ms |
1484 KB |
Output is correct |
46 |
Correct |
1 ms |
1484 KB |
Output is correct |
47 |
Correct |
2 ms |
1488 KB |
Output is correct |
48 |
Correct |
1 ms |
1484 KB |
Output is correct |
49 |
Correct |
4 ms |
2124 KB |
Output is correct |
50 |
Correct |
5 ms |
1868 KB |
Output is correct |
51 |
Correct |
7 ms |
1740 KB |
Output is correct |
52 |
Correct |
6 ms |
1748 KB |
Output is correct |
53 |
Correct |
67 ms |
22128 KB |
Output is correct |
54 |
Correct |
139 ms |
10352 KB |
Output is correct |
55 |
Correct |
154 ms |
10612 KB |
Output is correct |
56 |
Correct |
124 ms |
10112 KB |
Output is correct |
57 |
Correct |
206 ms |
10448 KB |
Output is correct |
58 |
Correct |
73 ms |
22724 KB |
Output is correct |
59 |
Correct |
115 ms |
13776 KB |
Output is correct |