# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1021085 |
2024-07-12T13:48:07 Z |
anton |
Wombats (IOI13_wombats) |
C++17 |
|
11415 ms |
241920 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 = 15;
const int BLOCK_NB = 335;
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 |
5 ms |
4700 KB |
Output is correct |
2 |
Correct |
5 ms |
4700 KB |
Output is correct |
3 |
Correct |
46 ms |
6384 KB |
Output is correct |
4 |
Correct |
5 ms |
4700 KB |
Output is correct |
5 |
Correct |
4 ms |
4864 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
3164 KB |
Output is correct |
5 |
Correct |
3 ms |
3164 KB |
Output is correct |
6 |
Correct |
4 ms |
3164 KB |
Output is correct |
7 |
Correct |
3 ms |
3164 KB |
Output is correct |
8 |
Correct |
2 ms |
3048 KB |
Output is correct |
9 |
Correct |
4 ms |
3164 KB |
Output is correct |
10 |
Correct |
4 ms |
2908 KB |
Output is correct |
11 |
Correct |
49 ms |
4080 KB |
Output is correct |
12 |
Correct |
3 ms |
3184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
339 ms |
45400 KB |
Output is correct |
2 |
Correct |
385 ms |
45016 KB |
Output is correct |
3 |
Correct |
379 ms |
45476 KB |
Output is correct |
4 |
Correct |
395 ms |
45396 KB |
Output is correct |
5 |
Correct |
367 ms |
44804 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1559 ms |
45472 KB |
Output is correct |
10 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
8796 KB |
Output is correct |
2 |
Correct |
16 ms |
8796 KB |
Output is correct |
3 |
Correct |
10 ms |
8792 KB |
Output is correct |
4 |
Correct |
30 ms |
9552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
353 ms |
45472 KB |
Output is correct |
2 |
Correct |
343 ms |
44772 KB |
Output is correct |
3 |
Correct |
360 ms |
45648 KB |
Output is correct |
4 |
Correct |
435 ms |
45396 KB |
Output is correct |
5 |
Correct |
384 ms |
44764 KB |
Output is correct |
6 |
Correct |
8 ms |
8796 KB |
Output is correct |
7 |
Correct |
8 ms |
8796 KB |
Output is correct |
8 |
Correct |
10 ms |
8796 KB |
Output is correct |
9 |
Correct |
41 ms |
9616 KB |
Output is correct |
10 |
Correct |
5 ms |
4696 KB |
Output is correct |
11 |
Correct |
6 ms |
4700 KB |
Output is correct |
12 |
Correct |
55 ms |
6304 KB |
Output is correct |
13 |
Correct |
10 ms |
4700 KB |
Output is correct |
14 |
Correct |
7 ms |
4700 KB |
Output is correct |
15 |
Correct |
1 ms |
856 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
600 KB |
Output is correct |
18 |
Correct |
2 ms |
3176 KB |
Output is correct |
19 |
Correct |
4 ms |
3164 KB |
Output is correct |
20 |
Correct |
4 ms |
3160 KB |
Output is correct |
21 |
Correct |
2 ms |
3164 KB |
Output is correct |
22 |
Correct |
2 ms |
2908 KB |
Output is correct |
23 |
Correct |
2 ms |
3164 KB |
Output is correct |
24 |
Correct |
2 ms |
3052 KB |
Output is correct |
25 |
Correct |
44 ms |
4072 KB |
Output is correct |
26 |
Correct |
2 ms |
3160 KB |
Output is correct |
27 |
Correct |
1568 ms |
45480 KB |
Output is correct |
28 |
Correct |
2691 ms |
71504 KB |
Output is correct |
29 |
Correct |
2725 ms |
66776 KB |
Output is correct |
30 |
Correct |
2608 ms |
66868 KB |
Output is correct |
31 |
Correct |
2630 ms |
72752 KB |
Output is correct |
32 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
329 ms |
45364 KB |
Output is correct |
2 |
Correct |
332 ms |
44892 KB |
Output is correct |
3 |
Correct |
385 ms |
45432 KB |
Output is correct |
4 |
Correct |
352 ms |
45392 KB |
Output is correct |
5 |
Correct |
343 ms |
45024 KB |
Output is correct |
6 |
Correct |
10 ms |
8792 KB |
Output is correct |
7 |
Correct |
9 ms |
8796 KB |
Output is correct |
8 |
Correct |
9 ms |
8796 KB |
Output is correct |
9 |
Correct |
31 ms |
9632 KB |
Output is correct |
10 |
Correct |
5 ms |
4700 KB |
Output is correct |
11 |
Correct |
5 ms |
4700 KB |
Output is correct |
12 |
Correct |
42 ms |
6224 KB |
Output is correct |
13 |
Correct |
5 ms |
4700 KB |
Output is correct |
14 |
Correct |
5 ms |
4872 KB |
Output is correct |
15 |
Correct |
4792 ms |
240220 KB |
Output is correct |
16 |
Correct |
11415 ms |
241920 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
2 ms |
3164 KB |
Output is correct |
21 |
Correct |
2 ms |
3164 KB |
Output is correct |
22 |
Correct |
2 ms |
3140 KB |
Output is correct |
23 |
Correct |
2 ms |
3164 KB |
Output is correct |
24 |
Correct |
2 ms |
2908 KB |
Output is correct |
25 |
Correct |
2 ms |
3164 KB |
Output is correct |
26 |
Correct |
2 ms |
2908 KB |
Output is correct |
27 |
Correct |
46 ms |
4100 KB |
Output is correct |
28 |
Correct |
2 ms |
3160 KB |
Output is correct |
29 |
Correct |
1482 ms |
45392 KB |
Output is correct |
30 |
Correct |
2540 ms |
71508 KB |
Output is correct |
31 |
Correct |
10846 ms |
241080 KB |
Output is correct |
32 |
Correct |
11127 ms |
241180 KB |
Output is correct |
33 |
Correct |
2543 ms |
66896 KB |
Output is correct |
34 |
Correct |
10543 ms |
228316 KB |
Output is correct |
35 |
Correct |
2600 ms |
66788 KB |
Output is correct |
36 |
Correct |
10899 ms |
228352 KB |
Output is correct |
37 |
Correct |
2569 ms |
72532 KB |
Output is correct |
38 |
Correct |
10995 ms |
241720 KB |
Output is correct |
39 |
Correct |
1 ms |
856 KB |
Output is correct |
40 |
Correct |
11041 ms |
228316 KB |
Output is correct |