Submission #1020988

# Submission time Handle Problem Language Result Execution time Memory
1020988 2024-07-12T12:37:52 Z anton Wombats (IOI13_wombats) C++17
55 / 100
20000 ms 26740 KB
#include "wombats.h"
#include<bits/stdc++.h>

using namespace std;

const int MAX_C= 200;
const int MAX_R = 5000;

struct Step{
    vector<vector<int>> tr;

    Step(){};
    Step(int nbC){
        tr.resize(nbC, vector<int> (nbC, 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;
}


vector<int> lr[MAX_R], d[MAX_R];
Step total;
int nbR;

void recalc_all(){
    total = Step(nbC, lr[0], d[0]);
    for(int i = 1; i<nbR; i++){
        //total.display();
        //steps[i].display();
        total = merge(total, Step(nbC, lr[i], d[i]));
        total.display();
    }
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
    nbC = C;
    nbR = R;
    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();
    }
    recalc_all();

}

void changeH(int P, int Q, int W) {
    lr[P][Q] = W;
    recalc_all();
}

void changeV(int P, int Q, int W) {
    d[P][Q] = W;
    recalc_all();
}

int escape(int V1, int V2) {
    return total.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:19:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   19 |         assert(lr.size() == nbC-1);
      |                ~~~~~~~~~~^~~~~~~~
wombats.cpp:20:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |         assert(d.size() == nbC);
      |                ~~~~~~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 334 ms 5084 KB Output is correct
2 Correct 336 ms 5200 KB Output is correct
3 Correct 370 ms 6484 KB Output is correct
4 Correct 406 ms 4956 KB Output is correct
5 Correct 343 ms 4956 KB Output is correct
6 Correct 0 ms 604 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 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 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2820 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 42 ms 3672 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1262 ms 3020 KB Output is correct
2 Correct 1225 ms 2904 KB Output is correct
3 Correct 1255 ms 2992 KB Output is correct
4 Correct 1242 ms 2996 KB Output is correct
5 Correct 1293 ms 2904 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 6167 ms 3012 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 500 ms 8796 KB Output is correct
2 Correct 515 ms 8792 KB Output is correct
3 Correct 550 ms 8796 KB Output is correct
4 Correct 553 ms 9404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1298 ms 2996 KB Output is correct
2 Correct 1229 ms 2904 KB Output is correct
3 Correct 1291 ms 2996 KB Output is correct
4 Correct 1339 ms 2904 KB Output is correct
5 Correct 1323 ms 856 KB Output is correct
6 Correct 542 ms 8796 KB Output is correct
7 Correct 526 ms 8796 KB Output is correct
8 Correct 536 ms 8796 KB Output is correct
9 Correct 535 ms 9556 KB Output is correct
10 Correct 385 ms 4956 KB Output is correct
11 Correct 336 ms 4956 KB Output is correct
12 Correct 372 ms 6484 KB Output is correct
13 Correct 336 ms 5084 KB Output is correct
14 Correct 378 ms 5084 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 46 ms 3744 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 6184 ms 3020 KB Output is correct
28 Execution timed out 20045 ms 12624 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1258 ms 2996 KB Output is correct
2 Correct 1257 ms 2908 KB Output is correct
3 Correct 1271 ms 2996 KB Output is correct
4 Correct 1318 ms 2908 KB Output is correct
5 Correct 1220 ms 2908 KB Output is correct
6 Correct 508 ms 8792 KB Output is correct
7 Correct 512 ms 8792 KB Output is correct
8 Correct 496 ms 8792 KB Output is correct
9 Correct 553 ms 9664 KB Output is correct
10 Correct 342 ms 4956 KB Output is correct
11 Correct 370 ms 4956 KB Output is correct
12 Correct 366 ms 6484 KB Output is correct
13 Correct 352 ms 5080 KB Output is correct
14 Correct 334 ms 5204 KB Output is correct
15 Correct 13606 ms 26740 KB Output is correct
16 Execution timed out 20057 ms 24868 KB Time limit exceeded
17 Halted 0 ms 0 KB -