답안 #1020981

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1020981 2024-07-12T12:32:51 Z anton 웜뱃 (IOI13_wombats) C++17
55 / 100
20000 ms 262144 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<Step> steps;
vector<int> lr[MAX_R], d[MAX_R];
Step total;

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

void changeV(int P, int Q, int W) {
    d[P][Q] = W;
    steps[P] = Step(nbC, lr[P], d[P]);
    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);
      |                ~~~~~~~~~^~~~~~
wombats.cpp: In function 'void recalc_all()':
wombats.cpp:90:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Step>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |     for(int i = 1; i<steps.size(); i++){
      |                    ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 151 ms 5468 KB Output is correct
2 Correct 145 ms 5468 KB Output is correct
3 Correct 185 ms 8204 KB Output is correct
4 Correct 144 ms 5468 KB Output is correct
5 Correct 144 ms 5488 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 860 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 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 39 ms 4976 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1223 ms 7216 KB Output is correct
2 Correct 1123 ms 7168 KB Output is correct
3 Correct 1170 ms 7268 KB Output is correct
4 Correct 1161 ms 7264 KB Output is correct
5 Correct 1139 ms 7212 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 5605 ms 7360 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 248 ms 9808 KB Output is correct
2 Correct 237 ms 9564 KB Output is correct
3 Correct 258 ms 9816 KB Output is correct
4 Correct 263 ms 10128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1154 ms 7004 KB Output is correct
2 Correct 1104 ms 7000 KB Output is correct
3 Correct 1179 ms 7260 KB Output is correct
4 Correct 1216 ms 7260 KB Output is correct
5 Correct 1218 ms 7004 KB Output is correct
6 Correct 264 ms 9564 KB Output is correct
7 Correct 235 ms 9448 KB Output is correct
8 Correct 255 ms 9564 KB Output is correct
9 Correct 267 ms 10252 KB Output is correct
10 Correct 149 ms 5464 KB Output is correct
11 Correct 145 ms 5468 KB Output is correct
12 Correct 180 ms 8272 KB Output is correct
13 Correct 145 ms 5468 KB Output is correct
14 Correct 189 ms 5464 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 2804 KB Output is correct
25 Correct 42 ms 4980 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 5870 ms 7344 KB Output is correct
28 Execution timed out 20063 ms 231696 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1167 ms 7212 KB Output is correct
2 Correct 1188 ms 7000 KB Output is correct
3 Correct 1166 ms 7264 KB Output is correct
4 Correct 1165 ms 7264 KB Output is correct
5 Correct 1166 ms 7000 KB Output is correct
6 Correct 266 ms 9564 KB Output is correct
7 Correct 239 ms 9564 KB Output is correct
8 Correct 254 ms 9564 KB Output is correct
9 Correct 264 ms 10328 KB Output is correct
10 Correct 162 ms 5468 KB Output is correct
11 Correct 144 ms 5464 KB Output is correct
12 Correct 183 ms 8272 KB Output is correct
13 Correct 152 ms 5488 KB Output is correct
14 Correct 147 ms 5468 KB Output is correct
15 Runtime error 290 ms 262144 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -