# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
943805 |
2024-03-12T01:15:58 Z |
Pring |
Toll (BOI17_toll) |
C++17 |
|
61 ms |
38000 KB |
#include <bits/stdc++.h>
using namespace std;
#ifdef MIKU
const string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;
typedef array<array<int, 5>, 5> MK;
const int MXN = 50005, INF = 3.9e18;
int n, m, k, q;
MK bgd[MXN], emp;
MK operator+(MK a, MK b) {
MK ans = emp;
FOR(i, 0, k) FOR(j, 0, k) {
FOR(c, 0, k) ans[i][j] = min(ans[i][j], a[i][c] + b[c][j]);
}
return ans;
}
#define mid ((l + r) >> 1)
struct SMG {
MK val[MXN * 4];
vector<MK> v;
void build(int id, int l, int r) {
if (l + 1 == r) {
val[id] = bgd[l];
return;
}
build(id * 2 + 1, l, mid);
build(id * 2 + 2, mid, r);
val[id] = val[id * 2 + 1] + val[id * 2 + 2];
}
MK query(int id, int l, int r, int _l, int _r) {
if (_l <= l && r <= _r) return val[id];
if (_l < mid && mid < _r) return query(id * 2 + 1, l, mid, _l, _r) + query(id * 2 + 2, mid, r, _l, _r);
if (_l < mid) return query(id * 2 + 1, l, mid, _l, _r);
return query(id * 2 + 2, mid, r, _l, _r);
}
} smg;
#undef mid
void init() {
FOR(i, 0, 5) FOR(j, 0, 5) emp[i][j] = INF;
}
void PUSH_EDGE(MK &m, int x, int y, int z) {
m[x][y] = min(m[x][y], z);
}
void miku() {
int a, b, c;
cin >> k >> n >> m >> q;
int N = (n - 1) / k + 1;
fill(bgd, bgd + N, emp);
while (m--) {
cin >> a >> b >> c;
PUSH_EDGE(bgd[a / k], a % k, b % k, c);
}
smg.build(0, 0, N);
// MK ans = bgd[0] + bgd[1];
// FOR(i, 0, k) {
// FOR(j, 0, k) cout << (ans[i][j] == INF ? -1 : ans[i][j]) << ' ';
// cout << '\n';
// }
while (q--) {
cin >> a >> b;
if (a / k == b / k) {
cout << -1 << '\n';
continue;
}
debug(a / k, b / k);
MK ans = smg.query(0, 0, N, a / k, b / k);
// FOR(i, 0, k) {
// FOR(j, 0, k) cout << (ans[i][j] == INF ? -1 : ans[i][j]) << ' ';
// cout << '\n';
// }
cout << (ans[a % k][b % k] == INF ? -1 : ans[a % k][b % k]) << '\n';
}
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
init();
miku();
return 0;
}
Compilation message
toll.cpp: In function 'void miku()':
toll.cpp:11:20: warning: statement has no effect [-Wunused-value]
11 | #define debug(...) 39
| ^~
toll.cpp:87:9: note: in expansion of macro 'debug'
87 | debug(a / k, b / k);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
37968 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
4700 KB |
Output is correct |
6 |
Correct |
2 ms |
4584 KB |
Output is correct |
7 |
Correct |
2 ms |
4700 KB |
Output is correct |
8 |
Correct |
28 ms |
37980 KB |
Output is correct |
9 |
Correct |
30 ms |
37892 KB |
Output is correct |
10 |
Correct |
18 ms |
37224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
22620 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
5 ms |
4700 KB |
Output is correct |
8 |
Correct |
5 ms |
4696 KB |
Output is correct |
9 |
Correct |
33 ms |
36700 KB |
Output is correct |
10 |
Correct |
44 ms |
14660 KB |
Output is correct |
11 |
Correct |
42 ms |
21076 KB |
Output is correct |
12 |
Correct |
25 ms |
13660 KB |
Output is correct |
13 |
Correct |
34 ms |
9052 KB |
Output is correct |
14 |
Correct |
19 ms |
12124 KB |
Output is correct |
15 |
Correct |
21 ms |
6084 KB |
Output is correct |
16 |
Correct |
19 ms |
7820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
1000 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
2 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2904 KB |
Output is correct |
10 |
Correct |
36 ms |
36552 KB |
Output is correct |
11 |
Correct |
26 ms |
22612 KB |
Output is correct |
12 |
Correct |
39 ms |
13576 KB |
Output is correct |
13 |
Correct |
33 ms |
14676 KB |
Output is correct |
14 |
Correct |
42 ms |
19796 KB |
Output is correct |
15 |
Correct |
19 ms |
6748 KB |
Output is correct |
16 |
Correct |
16 ms |
7756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
1000 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
2 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2904 KB |
Output is correct |
10 |
Correct |
36 ms |
36552 KB |
Output is correct |
11 |
Correct |
26 ms |
22612 KB |
Output is correct |
12 |
Correct |
39 ms |
13576 KB |
Output is correct |
13 |
Correct |
33 ms |
14676 KB |
Output is correct |
14 |
Correct |
42 ms |
19796 KB |
Output is correct |
15 |
Correct |
19 ms |
6748 KB |
Output is correct |
16 |
Correct |
16 ms |
7756 KB |
Output is correct |
17 |
Correct |
34 ms |
19684 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
480 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
3 ms |
4580 KB |
Output is correct |
24 |
Correct |
3 ms |
4696 KB |
Output is correct |
25 |
Correct |
4 ms |
2652 KB |
Output is correct |
26 |
Correct |
3 ms |
2648 KB |
Output is correct |
27 |
Correct |
28 ms |
36692 KB |
Output is correct |
28 |
Correct |
35 ms |
14420 KB |
Output is correct |
29 |
Correct |
44 ms |
21332 KB |
Output is correct |
30 |
Correct |
37 ms |
19976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
37968 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
4700 KB |
Output is correct |
6 |
Correct |
2 ms |
4584 KB |
Output is correct |
7 |
Correct |
2 ms |
4700 KB |
Output is correct |
8 |
Correct |
28 ms |
37980 KB |
Output is correct |
9 |
Correct |
30 ms |
37892 KB |
Output is correct |
10 |
Correct |
18 ms |
37224 KB |
Output is correct |
11 |
Correct |
28 ms |
22620 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
5 ms |
4700 KB |
Output is correct |
18 |
Correct |
5 ms |
4696 KB |
Output is correct |
19 |
Correct |
33 ms |
36700 KB |
Output is correct |
20 |
Correct |
44 ms |
14660 KB |
Output is correct |
21 |
Correct |
42 ms |
21076 KB |
Output is correct |
22 |
Correct |
25 ms |
13660 KB |
Output is correct |
23 |
Correct |
34 ms |
9052 KB |
Output is correct |
24 |
Correct |
19 ms |
12124 KB |
Output is correct |
25 |
Correct |
21 ms |
6084 KB |
Output is correct |
26 |
Correct |
19 ms |
7820 KB |
Output is correct |
27 |
Correct |
1 ms |
2392 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
1 ms |
1000 KB |
Output is correct |
33 |
Correct |
1 ms |
4700 KB |
Output is correct |
34 |
Correct |
2 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
2904 KB |
Output is correct |
36 |
Correct |
36 ms |
36552 KB |
Output is correct |
37 |
Correct |
26 ms |
22612 KB |
Output is correct |
38 |
Correct |
39 ms |
13576 KB |
Output is correct |
39 |
Correct |
33 ms |
14676 KB |
Output is correct |
40 |
Correct |
42 ms |
19796 KB |
Output is correct |
41 |
Correct |
19 ms |
6748 KB |
Output is correct |
42 |
Correct |
16 ms |
7756 KB |
Output is correct |
43 |
Correct |
34 ms |
19684 KB |
Output is correct |
44 |
Correct |
1 ms |
2396 KB |
Output is correct |
45 |
Correct |
1 ms |
480 KB |
Output is correct |
46 |
Correct |
1 ms |
2396 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
2396 KB |
Output is correct |
49 |
Correct |
3 ms |
4580 KB |
Output is correct |
50 |
Correct |
3 ms |
4696 KB |
Output is correct |
51 |
Correct |
4 ms |
2652 KB |
Output is correct |
52 |
Correct |
3 ms |
2648 KB |
Output is correct |
53 |
Correct |
28 ms |
36692 KB |
Output is correct |
54 |
Correct |
35 ms |
14420 KB |
Output is correct |
55 |
Correct |
44 ms |
21332 KB |
Output is correct |
56 |
Correct |
37 ms |
19976 KB |
Output is correct |
57 |
Correct |
61 ms |
16284 KB |
Output is correct |
58 |
Correct |
31 ms |
38000 KB |
Output is correct |
59 |
Correct |
38 ms |
22860 KB |
Output is correct |