# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1021079 |
2024-07-12T13:43:34 Z |
anton |
Wombats (IOI13_wombats) |
C++17 |
|
13622 ms |
145120 KB |
#include "wombats.h"
#include<bits/stdc++.h>
using namespace std;
const int MAX_C= 200;
const int MAX_R = 5000;
const int INF= 1e9;
const int BLOCK_SZ = 25;
const int BLOCK_NB = 201;
struct Step{
vector<vector<int>> tr;
Step(){};
Step(int nbC){
tr.resize(nbC, vector<int> (nbC, INF));
for(int i = 0; i<nbC; i++){
tr[i][i] = 0;
}
}
Step(int nbC, vector<int> lr, vector<int> d){
assert(lr.size() == nbC-1);
assert(d.size() == nbC);
tr.resize(nbC, vector<int> (nbC, 0));
vector<int> prefCost(nbC);
for(int iC = 0; iC<nbC-1; iC++){
prefCost[iC+1] = prefCost[iC] + lr[iC];
}
for(int beginC = 0; beginC<nbC; beginC++){
for(int endC = 0; endC<nbC; endC++){
if(beginC<=endC){
tr[beginC][endC] = prefCost[endC] - prefCost[beginC] + d[endC];
}
else{
tr[beginC][endC] = prefCost[beginC] - prefCost[endC] + d[endC];
}
}
}
}
void display(){
/*for(int i = 0; i<tr.size(); i++){
for(auto e: tr[i]){
cout<<e<<" ";
}
cout<<endl;
}*/
}
};
int nbC;
void mergeBegin(Step &l, Step &r, Step&res, int Begin, int lMid, int rMid, int lEnd, int rEnd){
if(rEnd<lEnd){
return;
}
int splitEnd = (lEnd+rEnd)/2;
int minC= 1e9;
int minMid = (lMid+rMid)/2;
for(int iMid = lMid; iMid<=rMid; iMid++){
if(l.tr[Begin][iMid] + r.tr[iMid][splitEnd] < minC){
minMid= iMid;
minC = l.tr[Begin][iMid] + r.tr[iMid][splitEnd];
}
}
res.tr[Begin][splitEnd] = minC;
mergeBegin(l, r, res, Begin, lMid, minMid, lEnd, splitEnd-1);
mergeBegin(l, r, res, Begin, minMid, rMid, splitEnd+1, rEnd);
}
Step merge(Step& a, Step b){
Step res(nbC);
for(int iBegin = 0; iBegin<nbC; iBegin++){
mergeBegin(a, b, res, iBegin, 0, nbC-1, 0, nbC-1);
}
return res;
}
struct Tree{
int sz = 1;
vector<Step> tr;
Tree(){};
Tree(int l){
while(sz<l){
sz*=2;
}
tr.resize(2*sz, Step(nbC));
}
void upd(int i){
for(i/=2; i>=1; i/=2){
//cerr<<i<<endl;
tr[i] = merge(tr[i*2], tr[i*2+1]);
tr[i].display();
}
}
void set(int id, Step v){
tr[id+sz] = v;
upd(id+sz);
}
};
Tree tr;
Step steps[BLOCK_NB];
vector<int> lr[MAX_R], d[MAX_R];
Step total;
int nbR;
void recalc_block(int i){
steps[i] = Step(nbC);
for(int iR = i*BLOCK_SZ; iR<min((i+1)*BLOCK_SZ, nbR); iR++){
steps[i] = merge(steps[i], Step(nbC, lr[iR], d[iR]));
}
tr.set(i, steps[i]);
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
nbC = C;
nbR = R;
tr =Tree(BLOCK_NB);
for(int iR = 0; iR<R; iR++){
lr[iR].resize(C-1);
d[iR].resize(C);
for(int i = 0; i<C-1; i++){
lr[iR][i] = H[iR][i];
}
if(iR<R-1){
for(int i = 0; i<C; i++){
d[iR][i] = V[iR][i];
}
}
else{
for(int i = 0; i<C; i++){
d[iR][i] = 0;
}
}
//steps.push_back(Step(C, lr[iR], d[iR]));
//steps.back().display();
}
for(int i = 0; i<=(nbR)/BLOCK_SZ; i++){
recalc_block(i);
}
}
void changeH(int P, int Q, int W) {
lr[P][Q] = W;
recalc_block(P/BLOCK_SZ);
}
void changeV(int P, int Q, int W) {
d[P][Q] = W;
recalc_block(P/BLOCK_SZ);
}
int escape(int V1, int V2) {
return tr.tr[1].tr[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;
| ^~~
In file included from /usr/include/c++/10/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
from wombats.cpp:2:
wombats.cpp: In constructor 'Step::Step(int, std::vector<int>, std::vector<int>)':
wombats.cpp:24:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
24 | assert(lr.size() == nbC-1);
| ~~~~~~~~~~^~~~~~~~
wombats.cpp:25:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
25 | assert(d.size() == nbC);
| ~~~~~~~~~^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4700 KB |
Output is correct |
2 |
Correct |
5 ms |
4700 KB |
Output is correct |
3 |
Correct |
46 ms |
7508 KB |
Output is correct |
4 |
Correct |
6 ms |
4700 KB |
Output is correct |
5 |
Correct |
5 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
1756 KB |
Output is correct |
5 |
Correct |
2 ms |
1884 KB |
Output is correct |
6 |
Correct |
1 ms |
1884 KB |
Output is correct |
7 |
Correct |
1 ms |
1884 KB |
Output is correct |
8 |
Correct |
1 ms |
1884 KB |
Output is correct |
9 |
Correct |
2 ms |
1960 KB |
Output is correct |
10 |
Correct |
1 ms |
1884 KB |
Output is correct |
11 |
Correct |
44 ms |
4108 KB |
Output is correct |
12 |
Correct |
2 ms |
1884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
464 ms |
23608 KB |
Output is correct |
2 |
Correct |
425 ms |
23112 KB |
Output is correct |
3 |
Correct |
473 ms |
23224 KB |
Output is correct |
4 |
Correct |
461 ms |
23396 KB |
Output is correct |
5 |
Correct |
447 ms |
23172 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
2015 ms |
23480 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
8796 KB |
Output is correct |
2 |
Correct |
9 ms |
8792 KB |
Output is correct |
3 |
Correct |
10 ms |
8792 KB |
Output is correct |
4 |
Correct |
42 ms |
10324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
482 ms |
23440 KB |
Output is correct |
2 |
Correct |
438 ms |
23112 KB |
Output is correct |
3 |
Correct |
530 ms |
23632 KB |
Output is correct |
4 |
Correct |
466 ms |
23404 KB |
Output is correct |
5 |
Correct |
452 ms |
23128 KB |
Output is correct |
6 |
Correct |
10 ms |
8796 KB |
Output is correct |
7 |
Correct |
9 ms |
8856 KB |
Output is correct |
8 |
Correct |
9 ms |
8796 KB |
Output is correct |
9 |
Correct |
29 ms |
10140 KB |
Output is correct |
10 |
Correct |
5 ms |
4696 KB |
Output is correct |
11 |
Correct |
5 ms |
4608 KB |
Output is correct |
12 |
Correct |
43 ms |
7460 KB |
Output is correct |
13 |
Correct |
6 ms |
4696 KB |
Output is correct |
14 |
Correct |
5 ms |
4700 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
1892 KB |
Output is correct |
19 |
Correct |
1 ms |
1884 KB |
Output is correct |
20 |
Correct |
1 ms |
1884 KB |
Output is correct |
21 |
Correct |
1 ms |
1884 KB |
Output is correct |
22 |
Correct |
1 ms |
1836 KB |
Output is correct |
23 |
Correct |
2 ms |
1884 KB |
Output is correct |
24 |
Correct |
1 ms |
1884 KB |
Output is correct |
25 |
Correct |
44 ms |
4148 KB |
Output is correct |
26 |
Correct |
2 ms |
1880 KB |
Output is correct |
27 |
Correct |
2073 ms |
23396 KB |
Output is correct |
28 |
Correct |
2973 ms |
47476 KB |
Output is correct |
29 |
Correct |
3048 ms |
43544 KB |
Output is correct |
30 |
Correct |
3110 ms |
43604 KB |
Output is correct |
31 |
Correct |
3040 ms |
49232 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
446 ms |
23132 KB |
Output is correct |
2 |
Correct |
446 ms |
23112 KB |
Output is correct |
3 |
Correct |
461 ms |
23388 KB |
Output is correct |
4 |
Correct |
474 ms |
23636 KB |
Output is correct |
5 |
Correct |
482 ms |
23160 KB |
Output is correct |
6 |
Correct |
9 ms |
8792 KB |
Output is correct |
7 |
Correct |
9 ms |
8796 KB |
Output is correct |
8 |
Correct |
9 ms |
8964 KB |
Output is correct |
9 |
Correct |
31 ms |
10320 KB |
Output is correct |
10 |
Correct |
6 ms |
4700 KB |
Output is correct |
11 |
Correct |
5 ms |
4700 KB |
Output is correct |
12 |
Correct |
45 ms |
7588 KB |
Output is correct |
13 |
Correct |
5 ms |
4696 KB |
Output is correct |
14 |
Correct |
6 ms |
4700 KB |
Output is correct |
15 |
Correct |
3852 ms |
143800 KB |
Output is correct |
16 |
Correct |
13622 ms |
145120 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
1884 KB |
Output is correct |
21 |
Correct |
1 ms |
1884 KB |
Output is correct |
22 |
Correct |
2 ms |
1884 KB |
Output is correct |
23 |
Correct |
1 ms |
1880 KB |
Output is correct |
24 |
Correct |
1 ms |
1884 KB |
Output is correct |
25 |
Correct |
1 ms |
1884 KB |
Output is correct |
26 |
Correct |
2 ms |
1880 KB |
Output is correct |
27 |
Correct |
43 ms |
4176 KB |
Output is correct |
28 |
Correct |
2 ms |
1880 KB |
Output is correct |
29 |
Correct |
1996 ms |
23340 KB |
Output is correct |
30 |
Correct |
3132 ms |
47608 KB |
Output is correct |
31 |
Correct |
13269 ms |
142536 KB |
Output is correct |
32 |
Correct |
13164 ms |
142536 KB |
Output is correct |
33 |
Correct |
3067 ms |
43604 KB |
Output is correct |
34 |
Correct |
12499 ms |
133068 KB |
Output is correct |
35 |
Correct |
3026 ms |
43348 KB |
Output is correct |
36 |
Correct |
12681 ms |
133200 KB |
Output is correct |
37 |
Correct |
2955 ms |
49236 KB |
Output is correct |
38 |
Correct |
12763 ms |
143308 KB |
Output is correct |
39 |
Correct |
1 ms |
604 KB |
Output is correct |
40 |
Correct |
12719 ms |
133284 KB |
Output is correct |