Submission #286574

#TimeUsernameProblemLanguageResultExecution timeMemory
286574evpipisWombats (IOI13_wombats)C++11
76 / 100
20011 ms32168 KiB
#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;

const int len_n = 5005, len_m = 205, inf = 1e9+10;
int hor[len_n][len_m], ver[len_n][len_m], n, m, k;

struct{
    struct node{
        int to[len_m][len_m];

        node(){
            for (int a = 0; a < m; a++)
                for (int b = 0; b < m; b++)
                    to[a][b] = inf; // check this
        }

        node(int i){
            for (int a = 0, suma = 0; a < m; a++){
                for (int b = 0, dif = suma; b < m; b++){
                    to[a][b] = dif + ver[i][b];

                    if (b < a)
                        dif -= hor[i][b];
                    else
                        dif += hor[i][b];
                }

                suma += hor[i][a];
            }
        }
    };

    node buck[75], root, temp;
    int opt[len_m][len_m];

    node join(node &fir, node &sec){
        node res;

        for (int i = 0; i < m; i++)
            for (int j = (i==0?0:opt[i-1][i-1]); j < m; j++)
                if (fir.to[i][j]+sec.to[j][i] < res.to[i][i])
                    res.to[i][i] = fir.to[i][j]+sec.to[j][i], opt[i][i] = j;
        for (int sz = 2; sz <= m; sz++){
            for (int a = 0; a < m; a++){
                int b = a+sz-1;
                if (b < m)
                    for (int c = opt[a][b-1]; c <= opt[a+1][b]; c++)
                        if (fir.to[a][c]+sec.to[c][b] < res.to[a][b])
                            res.to[a][b] = fir.to[a][c]+sec.to[c][b], opt[a][b] = c;

                b = a-sz+1;
                if (b >= 0)
                    for (int c = opt[a][b+1]; c >= opt[a-1][b]; c--)
                        if (fir.to[a][c]+sec.to[c][b] < res.to[a][b])
                            res.to[a][b] = fir.to[a][c]+sec.to[c][b], opt[a][b] = c;
            }
            /*
            for (int a = 0, b = sz-1; b < m; a++, b++)
                for (int c = opt[a][b-1]; c <= opt[a+1][b]; c++)
                    if (fir.to[a][c]+sec.to[c][b] < res.to[a][b])
                        res.to[a][b] = fir.to[a][c]+sec.to[c][b], opt[a][b] = c;

            for (int b = 0, a = sz-1; a < m; a++, b++)
                for (int c = opt[a][b+1]; c >= opt[a-1][b]; c--)
                    if (fir.to[a][c]+sec.to[c][b] < res.to[a][b])
                        res.to[a][b] = fir.to[a][c]+sec.to[c][b], opt[a][b] = c;
            */
        }

        return res;
    }

    void upd_buck(int b){
        int st = b*k, en = min(n, (b+1)*k);

        buck[b] = node(st);
        for (int i = st+1; i < en; i++)
            temp = node(i), buck[b] = join(buck[b], temp);
    }

    void upd_root(){
        root = buck[0];
        for (int b = 1; b*k < n; b++)
            root = join(root, buck[b]);
    }

    int ask(int a, int b){
        return root.to[a][b];
    }
} data;

void init(int R, int C, int H[5000][200], int V[5000][200]) {
    n = R, m = C;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m-1; j++)
            hor[i][j] = H[i][j];
    for (int i = 0; i < n-1; i++)
        for (int j = 0; j < m; j++)
            ver[i][j] = V[i][j];

    k = sqrt(n);
    for (int b = 0; k*b < n; b++)
        data.upd_buck(b);
    data.upd_root();
}

void changeH(int P, int Q, int W) {
    hor[P][Q] = W;
    data.upd_buck(P/k);
    data.upd_root();
}

void changeV(int P, int Q, int W) {
    ver[P][Q] = W;
    data.upd_buck(P/k);
    data.upd_root();
}

int escape(int V1, int V2) {
    return data.ask(V1, V2);
}

Compilation message (stderr)

grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   15 |  int res;
      |      ^~~
wombats.cpp: In function 'void<unnamed struct>::upd_buck(int)':
wombats.cpp:79:18: warning: '<anonymous>' may be used uninitialized in this function [-Wmaybe-uninitialized]
   79 |             temp = node(i), buck[b] = join(buck[b], temp);
      |             ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...