# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
998757 |
2024-06-14T16:13:21 Z |
iah |
Toll (BOI17_toll) |
C++14 |
|
126 ms |
72160 KB |
#include<bits/stdc++.h>
using namespace std;
#define NAME ""
#define ll long long
#define pii pair < int , int >
#define fi first
#define se second
#define bit(x, i) (((x) >> (i)) & 1ll)
#define mask(x) (1ll << (x))
#define mem(f, x) memset(f, x, sizeof(f))
#define sz(x) (int32_t) (x.size())
constexpr int inf = 1e9;
int k;
vector < vector < vector < vector < int > > > > d;
vector < vector < int > > ans, tmp;
void combine(vector < vector < int > > &res, vector < vector < int > > &a, vector < vector < int > > &b) {
for (int x = 0; x < k; x ++) {
for (int y = 0; y < k; y ++) {
for (int z = 0; z < k; z ++) {
res[x][y] = min(res[x][y], a[x][z] + b[z][y]);
}
}
}
}
signed main() {
if (fopen(NAME".inp", "r")) {
freopen(NAME".inp", "r", stdin);
freopen(NAME".out", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
int n, m, q;
cin >> k >> n >> m >> q;
n --;
n /= k;
d.assign(n + 1, vector < vector < vector < int > > > (16, vector < vector < int > > (k, vector < int > (k, inf))));
ans.assign(k, vector < int > (k, 0));
tmp.assign(k, vector < int > (k, 0));
for (; m --;) {
int u, v, w;
cin >> u >> v >> w;
int i = u / k;
u %= k;
v %= k;
d[i][0][u][v] = w;
}
for (int j = 1; mask(j) <= n; j ++) {
for (int i = 0; i + mask(j) <= n; i ++) {
combine(d[i][j], d[i][j - 1], d[i + mask(j - 1)][j - 1]);
// cout << j << " " << i << " " << i + mask(j - 1) << "\n";
// for (int x = 0; x < k; x ++) {
// for (auto y = 0; y < k; y ++) {
// cout << d[i][j][x][y] << " ";
// }
// cout << "\n";
// }
// cout << "\n";
}
}
for (; q --;) {
int u, v;
cin >> u >> v;
int diff = (v / k) - (u / k), stair = u / k;
for (int i = 0; i < k; i ++) {
for (int j = 0; j < k; j ++) {
if (i != j) {
ans[i][j] = inf;
}
else {
ans[i][j] = 0;
}
}
}
if (diff < 0) {
for (int i = 0; i < k; i ++) {
for (int j = 0; j < k; j ++) {
ans[i][j] = inf;
}
}
}
for (int j = 0; mask(j) <= diff; j ++) {
if (bit(diff, j) && diff > 0) {
swap(ans, tmp);
for (int i = 0; i < k; i ++) {
for (int j = 0; j < k; j ++) {
ans[i][j] = inf;
}
}
combine(ans, tmp, d[stair][j]);
stair += mask(j);
}
}
u %= k;
v %= k;
cout << (ans[u % k][v % k] == inf ? -1: ans[u % k][v % k]) << "\n";
}
return 0;
}
Compilation message
toll.cpp: In function 'int main()':
toll.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen(NAME".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:34:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | freopen(NAME".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
106 ms |
71248 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
1884 KB |
Output is correct |
6 |
Correct |
2 ms |
1628 KB |
Output is correct |
7 |
Correct |
2 ms |
1628 KB |
Output is correct |
8 |
Correct |
108 ms |
71276 KB |
Output is correct |
9 |
Correct |
109 ms |
71168 KB |
Output is correct |
10 |
Correct |
90 ms |
71228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
104 ms |
60912 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
1876 KB |
Output is correct |
8 |
Correct |
4 ms |
1628 KB |
Output is correct |
9 |
Correct |
105 ms |
72056 KB |
Output is correct |
10 |
Correct |
97 ms |
55380 KB |
Output is correct |
11 |
Correct |
106 ms |
62548 KB |
Output is correct |
12 |
Correct |
89 ms |
54352 KB |
Output is correct |
13 |
Correct |
70 ms |
32340 KB |
Output is correct |
14 |
Correct |
62 ms |
33620 KB |
Output is correct |
15 |
Correct |
56 ms |
31200 KB |
Output is correct |
16 |
Correct |
56 ms |
31024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
1884 KB |
Output is correct |
7 |
Correct |
2 ms |
1624 KB |
Output is correct |
8 |
Correct |
2 ms |
1428 KB |
Output is correct |
9 |
Correct |
2 ms |
1372 KB |
Output is correct |
10 |
Correct |
99 ms |
72064 KB |
Output is correct |
11 |
Correct |
94 ms |
62420 KB |
Output is correct |
12 |
Correct |
90 ms |
55376 KB |
Output is correct |
13 |
Correct |
97 ms |
55636 KB |
Output is correct |
14 |
Correct |
85 ms |
54912 KB |
Output is correct |
15 |
Correct |
53 ms |
31068 KB |
Output is correct |
16 |
Correct |
54 ms |
31060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
1884 KB |
Output is correct |
7 |
Correct |
2 ms |
1624 KB |
Output is correct |
8 |
Correct |
2 ms |
1428 KB |
Output is correct |
9 |
Correct |
2 ms |
1372 KB |
Output is correct |
10 |
Correct |
99 ms |
72064 KB |
Output is correct |
11 |
Correct |
94 ms |
62420 KB |
Output is correct |
12 |
Correct |
90 ms |
55376 KB |
Output is correct |
13 |
Correct |
97 ms |
55636 KB |
Output is correct |
14 |
Correct |
85 ms |
54912 KB |
Output is correct |
15 |
Correct |
53 ms |
31068 KB |
Output is correct |
16 |
Correct |
54 ms |
31060 KB |
Output is correct |
17 |
Correct |
94 ms |
62288 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
3 ms |
1716 KB |
Output is correct |
24 |
Correct |
2 ms |
1628 KB |
Output is correct |
25 |
Correct |
4 ms |
1496 KB |
Output is correct |
26 |
Correct |
3 ms |
1372 KB |
Output is correct |
27 |
Correct |
101 ms |
72016 KB |
Output is correct |
28 |
Correct |
102 ms |
55376 KB |
Output is correct |
29 |
Correct |
104 ms |
55652 KB |
Output is correct |
30 |
Correct |
90 ms |
55124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
106 ms |
71248 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
1884 KB |
Output is correct |
6 |
Correct |
2 ms |
1628 KB |
Output is correct |
7 |
Correct |
2 ms |
1628 KB |
Output is correct |
8 |
Correct |
108 ms |
71276 KB |
Output is correct |
9 |
Correct |
109 ms |
71168 KB |
Output is correct |
10 |
Correct |
90 ms |
71228 KB |
Output is correct |
11 |
Correct |
104 ms |
60912 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
4 ms |
1876 KB |
Output is correct |
18 |
Correct |
4 ms |
1628 KB |
Output is correct |
19 |
Correct |
105 ms |
72056 KB |
Output is correct |
20 |
Correct |
97 ms |
55380 KB |
Output is correct |
21 |
Correct |
106 ms |
62548 KB |
Output is correct |
22 |
Correct |
89 ms |
54352 KB |
Output is correct |
23 |
Correct |
70 ms |
32340 KB |
Output is correct |
24 |
Correct |
62 ms |
33620 KB |
Output is correct |
25 |
Correct |
56 ms |
31200 KB |
Output is correct |
26 |
Correct |
56 ms |
31024 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
1884 KB |
Output is correct |
33 |
Correct |
2 ms |
1624 KB |
Output is correct |
34 |
Correct |
2 ms |
1428 KB |
Output is correct |
35 |
Correct |
2 ms |
1372 KB |
Output is correct |
36 |
Correct |
99 ms |
72064 KB |
Output is correct |
37 |
Correct |
94 ms |
62420 KB |
Output is correct |
38 |
Correct |
90 ms |
55376 KB |
Output is correct |
39 |
Correct |
97 ms |
55636 KB |
Output is correct |
40 |
Correct |
85 ms |
54912 KB |
Output is correct |
41 |
Correct |
53 ms |
31068 KB |
Output is correct |
42 |
Correct |
54 ms |
31060 KB |
Output is correct |
43 |
Correct |
94 ms |
62288 KB |
Output is correct |
44 |
Correct |
0 ms |
344 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
344 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
3 ms |
1716 KB |
Output is correct |
50 |
Correct |
2 ms |
1628 KB |
Output is correct |
51 |
Correct |
4 ms |
1496 KB |
Output is correct |
52 |
Correct |
3 ms |
1372 KB |
Output is correct |
53 |
Correct |
101 ms |
72016 KB |
Output is correct |
54 |
Correct |
102 ms |
55376 KB |
Output is correct |
55 |
Correct |
104 ms |
55652 KB |
Output is correct |
56 |
Correct |
90 ms |
55124 KB |
Output is correct |
57 |
Correct |
126 ms |
55888 KB |
Output is correct |
58 |
Correct |
112 ms |
72160 KB |
Output is correct |
59 |
Correct |
107 ms |
62544 KB |
Output is correct |