# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
542725 |
2022-03-27T17:54:09 Z |
skittles1412 |
Toll (BOI17_toll) |
C++17 |
|
73 ms |
30596 KB |
#include "bits/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
<< ": "; \
dbgh(__VA_ARGS__)
#else
#define cerr \
if (false) \
cerr
#define dbg(...)
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())
using Mat = array<array<int, 5>, 5>;
Mat matinf() {
Mat ans;
for (auto& a : ans) {
fill(begin(a), end(a), 1e9);
}
return ans;
}
Mat operator+(const Mat& x, const Mat& y) {
Mat ans = matinf();
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
for (int k = 0; k < 5; k++) {
ans[i][k] = min(ans[i][k], x[i][j] + y[j][k]);
}
}
}
return ans;
}
struct ST {
int n;
vector<Mat> arr, v;
ST(const vector<Mat>& arr) : n(sz(arr)), arr(arr), v(4 * n) {
build(1, 0, n - 1);
}
void build(int o, int l, int r) {
if (l == r) {
v[o] = arr[l];
} else {
int mid = (l + r) / 2, lc = o * 2, rc = lc + 1;
build(lc, l, mid);
build(rc, mid + 1, r);
v[o] = v[lc] + v[rc];
}
}
Mat query(int o, int l, int r, int ql, int qr) const {
if (ql <= l && r <= qr) {
return v[o];
} else {
int mid = (l + r) / 2, lc = o * 2, rc = lc + 1;
if (ql <= mid) {
if (mid < qr) {
return query(lc, l, mid, ql, qr) + query(rc, mid + 1, r, ql, qr);
}
return query(lc, l, mid, ql, qr);
}
return query(rc, mid + 1, r, ql, qr);
}
}
Mat query(int l, int r) const {
return query(1, 0, n - 1, l, r);
}
};
void solve() {
int k, n, m, q;
cin >> k >> n >> m >> q;
vector<Mat> arr(n / k + 1, matinf());
for (int i = 0; i < m; i++) {
int u, v, w;
cin >> u >> v >> w;
arr[u / k][u % k][v % k] = w;
}
ST st(arr);
while (q--) {
int u, v;
cin >> u >> v;
if (u / k >= v / k) {
if (u == v) {
cout << 0 << endl;
} else {
cout << -1 << endl;
}
continue;
}
Mat ans = st.query(u / k, v / k - 1);
int cans = ans[u % k][v % k];
if (cans < int(1e9)) {
cout << cans << endl;
} else {
cout << -1 << endl;
}
}
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cin.exceptions(ios::failbit);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
30596 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
3 ms |
924 KB |
Output is correct |
6 |
Correct |
3 ms |
820 KB |
Output is correct |
7 |
Correct |
3 ms |
852 KB |
Output is correct |
8 |
Correct |
66 ms |
30596 KB |
Output is correct |
9 |
Correct |
72 ms |
30564 KB |
Output is correct |
10 |
Correct |
62 ms |
29800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
16588 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
11 ms |
980 KB |
Output is correct |
8 |
Correct |
10 ms |
732 KB |
Output is correct |
9 |
Correct |
59 ms |
30564 KB |
Output is correct |
10 |
Correct |
63 ms |
12428 KB |
Output is correct |
11 |
Correct |
56 ms |
16700 KB |
Output is correct |
12 |
Correct |
44 ms |
11400 KB |
Output is correct |
13 |
Correct |
46 ms |
6256 KB |
Output is correct |
14 |
Correct |
33 ms |
7628 KB |
Output is correct |
15 |
Correct |
29 ms |
5072 KB |
Output is correct |
16 |
Correct |
25 ms |
5068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
852 KB |
Output is correct |
7 |
Correct |
2 ms |
584 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
42 ms |
30420 KB |
Output is correct |
11 |
Correct |
44 ms |
16444 KB |
Output is correct |
12 |
Correct |
49 ms |
12236 KB |
Output is correct |
13 |
Correct |
51 ms |
12428 KB |
Output is correct |
14 |
Correct |
40 ms |
11856 KB |
Output is correct |
15 |
Correct |
21 ms |
5004 KB |
Output is correct |
16 |
Correct |
21 ms |
5000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
852 KB |
Output is correct |
7 |
Correct |
2 ms |
584 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
42 ms |
30420 KB |
Output is correct |
11 |
Correct |
44 ms |
16444 KB |
Output is correct |
12 |
Correct |
49 ms |
12236 KB |
Output is correct |
13 |
Correct |
51 ms |
12428 KB |
Output is correct |
14 |
Correct |
40 ms |
11856 KB |
Output is correct |
15 |
Correct |
21 ms |
5004 KB |
Output is correct |
16 |
Correct |
21 ms |
5000 KB |
Output is correct |
17 |
Correct |
49 ms |
16576 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
324 KB |
Output is correct |
22 |
Correct |
1 ms |
324 KB |
Output is correct |
23 |
Correct |
6 ms |
968 KB |
Output is correct |
24 |
Correct |
6 ms |
652 KB |
Output is correct |
25 |
Correct |
4 ms |
468 KB |
Output is correct |
26 |
Correct |
5 ms |
468 KB |
Output is correct |
27 |
Correct |
44 ms |
30516 KB |
Output is correct |
28 |
Correct |
50 ms |
12308 KB |
Output is correct |
29 |
Correct |
56 ms |
12560 KB |
Output is correct |
30 |
Correct |
40 ms |
11988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
30596 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
3 ms |
924 KB |
Output is correct |
6 |
Correct |
3 ms |
820 KB |
Output is correct |
7 |
Correct |
3 ms |
852 KB |
Output is correct |
8 |
Correct |
66 ms |
30596 KB |
Output is correct |
9 |
Correct |
72 ms |
30564 KB |
Output is correct |
10 |
Correct |
62 ms |
29800 KB |
Output is correct |
11 |
Correct |
53 ms |
16588 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
11 ms |
980 KB |
Output is correct |
18 |
Correct |
10 ms |
732 KB |
Output is correct |
19 |
Correct |
59 ms |
30564 KB |
Output is correct |
20 |
Correct |
63 ms |
12428 KB |
Output is correct |
21 |
Correct |
56 ms |
16700 KB |
Output is correct |
22 |
Correct |
44 ms |
11400 KB |
Output is correct |
23 |
Correct |
46 ms |
6256 KB |
Output is correct |
24 |
Correct |
33 ms |
7628 KB |
Output is correct |
25 |
Correct |
29 ms |
5072 KB |
Output is correct |
26 |
Correct |
25 ms |
5068 KB |
Output is correct |
27 |
Correct |
1 ms |
328 KB |
Output is correct |
28 |
Correct |
1 ms |
324 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
324 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
2 ms |
852 KB |
Output is correct |
33 |
Correct |
2 ms |
584 KB |
Output is correct |
34 |
Correct |
2 ms |
468 KB |
Output is correct |
35 |
Correct |
2 ms |
468 KB |
Output is correct |
36 |
Correct |
42 ms |
30420 KB |
Output is correct |
37 |
Correct |
44 ms |
16444 KB |
Output is correct |
38 |
Correct |
49 ms |
12236 KB |
Output is correct |
39 |
Correct |
51 ms |
12428 KB |
Output is correct |
40 |
Correct |
40 ms |
11856 KB |
Output is correct |
41 |
Correct |
21 ms |
5004 KB |
Output is correct |
42 |
Correct |
21 ms |
5000 KB |
Output is correct |
43 |
Correct |
49 ms |
16576 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
324 KB |
Output is correct |
48 |
Correct |
1 ms |
324 KB |
Output is correct |
49 |
Correct |
6 ms |
968 KB |
Output is correct |
50 |
Correct |
6 ms |
652 KB |
Output is correct |
51 |
Correct |
4 ms |
468 KB |
Output is correct |
52 |
Correct |
5 ms |
468 KB |
Output is correct |
53 |
Correct |
44 ms |
30516 KB |
Output is correct |
54 |
Correct |
50 ms |
12308 KB |
Output is correct |
55 |
Correct |
56 ms |
12560 KB |
Output is correct |
56 |
Correct |
40 ms |
11988 KB |
Output is correct |
57 |
Correct |
73 ms |
11000 KB |
Output is correct |
58 |
Correct |
61 ms |
30532 KB |
Output is correct |
59 |
Correct |
56 ms |
16716 KB |
Output is correct |