# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1067830 |
2024-08-21T04:07:59 Z |
Plurm |
Wombats (IOI13_wombats) |
C++11 |
|
19863 ms |
25944 KB |
#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;
int block_size;
int num_blocks;
int global_H[5000][200];
int global_V[5000][200];
int qsr[5000][200];
int C;
class BlockAnswer {
public:
vector<vector<int>> ans;
int rs, rt;
BlockAnswer(int r1, int r2) {
rs = r1;
rt = r2;
ans.resize(C);
for (int i = 0; i < C; i++) {
ans[i].resize(C, 1000000000);
}
}
virtual void update_i(int col) {
vector<int> dpst;
dpst.resize(C, 1000000000);
dpst[col] = 0;
for (int row = rs; row <= rt; row++) {
vector<int> dpnw;
dpnw.resize(C, 1000000000);
int pref = 1000000000;
for (int nc = 0; nc < C; nc++) {
pref = min(pref, dpst[nc] - qsr[row][nc]);
dpnw[nc] = pref + qsr[row][nc] + global_V[row][nc];
}
pref = 1000000000;
for (int nc = C - 1; nc >= 0; nc--) {
pref = min(pref, dpst[nc] + qsr[row][nc]);
dpnw[nc] =
min(dpnw[nc], pref - qsr[row][nc] + global_V[row][nc]);
}
swap(dpst, dpnw);
}
ans[col] = dpst;
}
void update() {
for (int i = 0; i < C; i++) {
update_i(i);
}
}
};
vector<BlockAnswer> blans;
void dcopt(vector<int> &dpnw, vector<int> &dpst, vector<vector<int>> &cost,
int ltarget, int rtarget, int lfound, int rfound) {
if (ltarget > rtarget)
return;
int mid = (ltarget + rtarget) / 2;
int idx = -1;
for (int oc = lfound; oc <= rfound; oc++) {
if (dpst[oc] + cost[oc][mid] < dpnw[mid]) {
dpnw[mid] = dpst[oc] + cost[oc][mid];
idx = oc;
}
}
dcopt(dpnw, dpst, cost, ltarget, mid - 1, lfound, idx);
dcopt(dpnw, dpst, cost, mid + 1, rtarget, idx, rfound);
}
class GlobalAnswer : public BlockAnswer {
public:
GlobalAnswer() : BlockAnswer(0, 0) {}
void update_i(int col) override {
vector<int> dpst;
dpst.resize(C, 1000000000);
dpst[col] = 0;
for (int blk = 0; blk < num_blocks; blk++) {
vector<int> dpnw;
dpnw.resize(C, 1000000000);
// DC opt?
dcopt(dpnw, dpst, blans[blk].ans, 0, C - 1, 0, C - 1);
swap(dpst, dpnw);
}
ans[col] = dpst;
}
};
GlobalAnswer *glob;
void init(int R, int C, int H[5000][200], int V[5000][200]) {
block_size = sqrt(R * max(1.0, log2(C)));
num_blocks = (R + block_size - 1) / block_size;
::C = C;
memcpy(global_H, H, 5000 * 200 * 4);
memcpy(global_V, V, 5000 * 200 * 4);
for (int j = 0; j < C; j++)
global_V[R - 1][j] = 0;
for (int j = 0; j < R; j++) {
qsr[j][0] = 0;
for (int i = 0; i < C - 1; i++) {
qsr[j][i + 1] = qsr[j][i] + global_H[j][i];
}
}
for (int i = 0; i < num_blocks; i++) {
int r1 = i * block_size;
int r2 = min((i + 1) * block_size - 1, R - 1);
blans.emplace_back(r1, r2);
blans.back().update();
}
glob = new GlobalAnswer();
glob->update();
}
void changeH(int P, int Q, int W) {
global_H[P][Q] = W;
for (int i = 0; i < C - 1; i++) {
qsr[P][i + 1] = qsr[P][i] + global_H[P][i];
}
blans[P / block_size].update();
glob->update();
}
void changeV(int P, int Q, int W) {
global_V[P][Q] = W;
blans[P / block_size].update();
glob->update();
}
int escape(int V1, int V2) { return glob->ans[V1][V2]; }
Compilation message
grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
15 | int res;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
15960 KB |
Output is correct |
2 |
Correct |
8 ms |
15964 KB |
Output is correct |
3 |
Correct |
47 ms |
17528 KB |
Output is correct |
4 |
Correct |
9 ms |
15960 KB |
Output is correct |
5 |
Correct |
8 ms |
16072 KB |
Output is correct |
6 |
Correct |
4 ms |
8284 KB |
Output is correct |
7 |
Correct |
5 ms |
8284 KB |
Output is correct |
8 |
Correct |
4 ms |
8284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8280 KB |
Output is correct |
2 |
Correct |
4 ms |
8284 KB |
Output is correct |
3 |
Correct |
4 ms |
8280 KB |
Output is correct |
4 |
Correct |
5 ms |
8284 KB |
Output is correct |
5 |
Correct |
4 ms |
8172 KB |
Output is correct |
6 |
Correct |
5 ms |
8284 KB |
Output is correct |
7 |
Correct |
4 ms |
8284 KB |
Output is correct |
8 |
Correct |
5 ms |
8284 KB |
Output is correct |
9 |
Correct |
5 ms |
8280 KB |
Output is correct |
10 |
Correct |
4 ms |
8284 KB |
Output is correct |
11 |
Correct |
44 ms |
9164 KB |
Output is correct |
12 |
Correct |
5 ms |
8280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
128 ms |
8540 KB |
Output is correct |
2 |
Correct |
120 ms |
8720 KB |
Output is correct |
3 |
Correct |
125 ms |
8724 KB |
Output is correct |
4 |
Correct |
122 ms |
8536 KB |
Output is correct |
5 |
Correct |
133 ms |
8540 KB |
Output is correct |
6 |
Correct |
4 ms |
8284 KB |
Output is correct |
7 |
Correct |
3 ms |
8284 KB |
Output is correct |
8 |
Correct |
4 ms |
8284 KB |
Output is correct |
9 |
Correct |
558 ms |
8540 KB |
Output is correct |
10 |
Correct |
5 ms |
8284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
19804 KB |
Output is correct |
2 |
Correct |
13 ms |
19904 KB |
Output is correct |
3 |
Correct |
14 ms |
19804 KB |
Output is correct |
4 |
Correct |
33 ms |
20732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
8540 KB |
Output is correct |
2 |
Correct |
117 ms |
8540 KB |
Output is correct |
3 |
Correct |
122 ms |
8724 KB |
Output is correct |
4 |
Correct |
122 ms |
8536 KB |
Output is correct |
5 |
Correct |
124 ms |
8536 KB |
Output is correct |
6 |
Correct |
13 ms |
20024 KB |
Output is correct |
7 |
Correct |
12 ms |
20008 KB |
Output is correct |
8 |
Correct |
13 ms |
19804 KB |
Output is correct |
9 |
Correct |
40 ms |
20792 KB |
Output is correct |
10 |
Correct |
9 ms |
15964 KB |
Output is correct |
11 |
Correct |
9 ms |
15964 KB |
Output is correct |
12 |
Correct |
46 ms |
17672 KB |
Output is correct |
13 |
Correct |
9 ms |
15960 KB |
Output is correct |
14 |
Correct |
12 ms |
15964 KB |
Output is correct |
15 |
Correct |
4 ms |
8284 KB |
Output is correct |
16 |
Correct |
5 ms |
8284 KB |
Output is correct |
17 |
Correct |
4 ms |
8284 KB |
Output is correct |
18 |
Correct |
4 ms |
8284 KB |
Output is correct |
19 |
Correct |
4 ms |
8284 KB |
Output is correct |
20 |
Correct |
4 ms |
8284 KB |
Output is correct |
21 |
Correct |
4 ms |
8284 KB |
Output is correct |
22 |
Correct |
5 ms |
8284 KB |
Output is correct |
23 |
Correct |
5 ms |
8284 KB |
Output is correct |
24 |
Correct |
4 ms |
8284 KB |
Output is correct |
25 |
Correct |
42 ms |
9220 KB |
Output is correct |
26 |
Correct |
5 ms |
8284 KB |
Output is correct |
27 |
Correct |
566 ms |
8536 KB |
Output is correct |
28 |
Correct |
4271 ms |
21436 KB |
Output is correct |
29 |
Correct |
4017 ms |
19296 KB |
Output is correct |
30 |
Correct |
3994 ms |
19248 KB |
Output is correct |
31 |
Correct |
4481 ms |
22608 KB |
Output is correct |
32 |
Correct |
4 ms |
8284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
119 ms |
8740 KB |
Output is correct |
2 |
Correct |
124 ms |
8716 KB |
Output is correct |
3 |
Correct |
122 ms |
8540 KB |
Output is correct |
4 |
Correct |
127 ms |
8720 KB |
Output is correct |
5 |
Correct |
119 ms |
8536 KB |
Output is correct |
6 |
Correct |
13 ms |
19800 KB |
Output is correct |
7 |
Correct |
12 ms |
19804 KB |
Output is correct |
8 |
Correct |
13 ms |
20024 KB |
Output is correct |
9 |
Correct |
32 ms |
20568 KB |
Output is correct |
10 |
Correct |
8 ms |
15964 KB |
Output is correct |
11 |
Correct |
8 ms |
15964 KB |
Output is correct |
12 |
Correct |
60 ms |
17464 KB |
Output is correct |
13 |
Correct |
8 ms |
15964 KB |
Output is correct |
14 |
Correct |
8 ms |
15892 KB |
Output is correct |
15 |
Correct |
774 ms |
24404 KB |
Output is correct |
16 |
Correct |
18993 ms |
25944 KB |
Output is correct |
17 |
Correct |
4 ms |
8280 KB |
Output is correct |
18 |
Correct |
4 ms |
8284 KB |
Output is correct |
19 |
Correct |
4 ms |
8284 KB |
Output is correct |
20 |
Correct |
4 ms |
8284 KB |
Output is correct |
21 |
Correct |
4 ms |
8152 KB |
Output is correct |
22 |
Correct |
4 ms |
8280 KB |
Output is correct |
23 |
Correct |
4 ms |
8284 KB |
Output is correct |
24 |
Correct |
4 ms |
8300 KB |
Output is correct |
25 |
Correct |
5 ms |
8284 KB |
Output is correct |
26 |
Correct |
4 ms |
8284 KB |
Output is correct |
27 |
Correct |
42 ms |
9288 KB |
Output is correct |
28 |
Correct |
4 ms |
8284 KB |
Output is correct |
29 |
Correct |
564 ms |
8704 KB |
Output is correct |
30 |
Correct |
4270 ms |
21464 KB |
Output is correct |
31 |
Correct |
17970 ms |
24928 KB |
Output is correct |
32 |
Correct |
18882 ms |
25084 KB |
Output is correct |
33 |
Correct |
4271 ms |
19344 KB |
Output is correct |
34 |
Correct |
17423 ms |
22624 KB |
Output is correct |
35 |
Correct |
4003 ms |
19280 KB |
Output is correct |
36 |
Correct |
17512 ms |
22616 KB |
Output is correct |
37 |
Correct |
4523 ms |
22484 KB |
Output is correct |
38 |
Correct |
18424 ms |
25680 KB |
Output is correct |
39 |
Correct |
4 ms |
8280 KB |
Output is correct |
40 |
Correct |
19863 ms |
22452 KB |
Output is correct |