Submission #286435

# Submission time Handle Problem Language Result Execution time Memory
286435 2020-08-30T11:47:19 Z evpipis Wombats (IOI13_wombats) C++11
39 / 100
20000 ms 30420 KB
#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; a < m; a++)
                for (int b = 0; b < m; b++)
                    to[a][b] = inf; // check this

            for (int a = 0, suma = 0; a < m; a++){
                for (int b = 0, sumb = 0; b < m; b++){
                    for (int c = 0, cura = suma, curb = sumb; c < m; c++){
                        to[a][b] = min(to[a][b], cura+ver[i][c]+curb);

                        if (c < a)
                            cura -= hor[i][c];
                        else
                            curb += hor[i][c];

                        if (c < b)
                            curb -= hor[i+1][c];
                        else
                            curb += hor[i+1][c];
                    }

                    sumb += hor[i+1][b];
                }

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

            if (0){
            printf("-------------------------------------------\n");
            printf("just constructed %d-th leaf\n", i);
            for (int a = 0; a < m; a++){
                for (int b = 0; b < m; b++)
                    printf("%d ", to[a][b]);
                printf("\n");
            }
            printf("-------------------------------------------\n");
            }
        }
    };

    node buck[75], root;

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

        for (int a = 0; a < m; a++)
            for (int b = 0; b < m; b++)
                for (int c = 0; c < m; c++)
                    res.to[a][b] = min(res.to[a][b], fir.to[a][c]+sec.to[c][b]);

        return res;
    }

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

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

    void upd_root(){
        root = buck[0];
        for (int b = 1; b*k < n-1; 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-1; b++)
        data.upd_buck(b);
    data.upd_root();
}

void changeH(int P, int Q, int W) {
    hor[P][Q] = W;
    if (P > 0)
        data.upd_buck((P-1)/k);
    if (P < n-1)
        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

grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   15 |  int res;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Correct 2901 ms 20824 KB Output is correct
2 Correct 2897 ms 20820 KB Output is correct
3 Correct 2973 ms 22544 KB Output is correct
4 Correct 2942 ms 20908 KB Output is correct
5 Correct 2896 ms 20728 KB Output is correct
6 Correct 1 ms 640 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 1 ms 640 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Correct 3 ms 1920 KB Output is correct
5 Correct 3 ms 1920 KB Output is correct
6 Correct 3 ms 1920 KB Output is correct
7 Correct 3 ms 1920 KB Output is correct
8 Correct 3 ms 1920 KB Output is correct
9 Correct 3 ms 1920 KB Output is correct
10 Correct 3 ms 1920 KB Output is correct
11 Correct 87 ms 4344 KB Output is correct
12 Correct 3 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5522 ms 3324 KB Output is correct
2 Correct 4216 ms 3276 KB Output is correct
3 Correct 7228 ms 3192 KB Output is correct
4 Correct 4485 ms 3192 KB Output is correct
5 Correct 5698 ms 3184 KB Output is correct
6 Correct 1 ms 640 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Execution timed out 20044 ms 3100 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3629 ms 28732 KB Output is correct
2 Correct 2945 ms 28732 KB Output is correct
3 Correct 3681 ms 28664 KB Output is correct
4 Correct 3594 ms 29640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5541 ms 3260 KB Output is correct
2 Correct 4151 ms 3192 KB Output is correct
3 Correct 7239 ms 3108 KB Output is correct
4 Correct 4423 ms 3184 KB Output is correct
5 Correct 5709 ms 3192 KB Output is correct
6 Correct 3536 ms 29048 KB Output is correct
7 Correct 2903 ms 28924 KB Output is correct
8 Correct 3630 ms 29176 KB Output is correct
9 Correct 3527 ms 30420 KB Output is correct
10 Correct 2920 ms 20844 KB Output is correct
11 Correct 2899 ms 20852 KB Output is correct
12 Correct 3006 ms 23708 KB Output is correct
13 Correct 2888 ms 20856 KB Output is correct
14 Correct 2904 ms 20856 KB Output is correct
15 Correct 1 ms 640 KB Output is correct
16 Correct 1 ms 640 KB Output is correct
17 Correct 1 ms 640 KB Output is correct
18 Correct 3 ms 1920 KB Output is correct
19 Correct 3 ms 1920 KB Output is correct
20 Correct 3 ms 1920 KB Output is correct
21 Correct 3 ms 1920 KB Output is correct
22 Correct 3 ms 1920 KB Output is correct
23 Correct 3 ms 1920 KB Output is correct
24 Correct 3 ms 1920 KB Output is correct
25 Correct 87 ms 4344 KB Output is correct
26 Correct 3 ms 1920 KB Output is correct
27 Execution timed out 20060 ms 3248 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5503 ms 3400 KB Output is correct
2 Correct 4117 ms 3264 KB Output is correct
3 Correct 7248 ms 3288 KB Output is correct
4 Correct 4414 ms 3188 KB Output is correct
5 Correct 5732 ms 3320 KB Output is correct
6 Correct 3546 ms 28860 KB Output is correct
7 Correct 2862 ms 28788 KB Output is correct
8 Correct 3595 ms 28920 KB Output is correct
9 Correct 3543 ms 30200 KB Output is correct
10 Correct 2884 ms 20852 KB Output is correct
11 Correct 2878 ms 20856 KB Output is correct
12 Correct 2970 ms 23672 KB Output is correct
13 Correct 2915 ms 20860 KB Output is correct
14 Correct 2915 ms 20868 KB Output is correct
15 Execution timed out 20075 ms 28584 KB Time limit exceeded
16 Halted 0 ms 0 KB -