Submission #680072

# Submission time Handle Problem Language Result Execution time Memory
680072 2023-01-09T21:01:06 Z bashkort Wombats (IOI13_wombats) C++17
100 / 100
10359 ms 68800 KB
#include <bits/stdc++.h>
#include "wombats.h"

using namespace std;

inline bool ckmin(int &a, int b) {
    return (a > b) && (a = b, true);
}

constexpr int B = 70, R = 5000, C = 200, K = (R + B - 1) / B + 1;
const int N = K * 2;

int r, c, need, sz = 1;
int dp[2 * N][C][C], fr[K][C][C], H[R][C], V[R][C];


void pull(int x) {
    memset(dp[x], 0x3f, sizeof(dp[x]));

    if (dp[x << 1 | 1][0][0] == -1) {
        memcpy(dp[x], dp[x << 1], sizeof(dp[x]));
        return;
    }

    for (int cc = 0; cc < c; ++cc) {
        auto solve = [&](auto solve, int l, int r, int optl, int optr) -> void {
            if (l >= r) {
                return;
            }

            int mid = (l + r) >> 1;

            int opt = optl;

            for (int b = optl; b <= optr; ++b) {
                if (ckmin(dp[x][cc][mid], dp[x << 1][cc][b] + dp[x << 1 | 1][b][mid])) {
                    opt = b;
                }
            }

            solve(solve, l, mid, optl, opt), solve(solve, mid + 1, r, opt, optr);
        };
        solve(solve, 0, c, 0, c - 1);
    }
}

void update_fr(int L) {
    if (L < 0) {
        return;
    }

    int lim = max(0, B * L - 1);

    if (lim < r) {
        memset(fr[L], 0x3f, sizeof(fr[L]));
        for (int a = 0; a < c; ++a) {
            fr[L][a][a] = 0;
        }

        for (int i = min(r, B * (L + 1)) - 1; i >= lim; --i) {
            for (int a = 0; a < c - 1; ++a) {
                for (int b = 0; b < c; ++b) {
                    ckmin(fr[L][a + 1][b], fr[L][a][b] + H[i][a]);
                }
            }
            for (int a = c - 2; a >= 0; --a) {
                for (int b = 0; b < c; ++b) {
                    ckmin(fr[L][a][b], fr[L][a + 1][b] + H[i][a]);
                }
            }

            if (i != lim) {
                for (int a = 0; a < c; ++a) {
                    for (int b = 0; b < c; ++b) {
                        fr[L][a][b] += V[i - 1][a];
                    }
                }
            }
        }

        memcpy(dp[sz + L], fr[L], sizeof(dp[sz + L]));
    } else {
        memset(dp[sz + L], -1, sizeof(dp[sz + L]));
    }

    for (int x = sz + L; x >>= 1;) {
        pull(x);
    }
}

void init(int R, int C, int H[5000][200], int V[5000][200]) {
    r = R, c = C;
    memcpy(::H, H, sizeof(::H)), memcpy(::V, V, sizeof(::V));

    need = r / B + 1;
    sz = 1 << __lg(need) + bool(need & (need - 1));
    for (int i = 0; i < sz; ++i) {
        update_fr(i);
    }
}

void changeH(int P, int Q, int W) {
    H[P][Q] = W;

    update_fr(P / B);
    if ((P + 1) % B == 0 && P / B + 1 < need) {
        update_fr(P / B + 1);
    }
}

void changeV(int P, int Q, int W) {
    V[P][Q] = W;

    update_fr((P + 1) / B);
}

int escape(int V1, int V2) {
    return dp[1][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;
      |      ^~~
wombats.cpp: In function 'void init(int, int, int (*)[200], int (*)[200])':
wombats.cpp:96:26: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   96 |     sz = 1 << __lg(need) + bool(need & (need - 1));
      |               ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 67 ms 63236 KB Output is correct
2 Correct 69 ms 63236 KB Output is correct
3 Correct 126 ms 64852 KB Output is correct
4 Correct 95 ms 63180 KB Output is correct
5 Correct 56 ms 63204 KB Output is correct
6 Correct 4 ms 8404 KB Output is correct
7 Correct 4 ms 8404 KB Output is correct
8 Correct 5 ms 8404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8404 KB Output is correct
2 Correct 4 ms 8404 KB Output is correct
3 Correct 5 ms 8404 KB Output is correct
4 Correct 5 ms 8404 KB Output is correct
5 Correct 5 ms 8404 KB Output is correct
6 Correct 6 ms 8404 KB Output is correct
7 Correct 5 ms 8424 KB Output is correct
8 Correct 5 ms 8404 KB Output is correct
9 Correct 5 ms 8396 KB Output is correct
10 Correct 6 ms 8404 KB Output is correct
11 Correct 68 ms 9388 KB Output is correct
12 Correct 6 ms 8404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 143 ms 9084 KB Output is correct
2 Correct 213 ms 9100 KB Output is correct
3 Correct 216 ms 9084 KB Output is correct
4 Correct 207 ms 9084 KB Output is correct
5 Correct 251 ms 9088 KB Output is correct
6 Correct 4 ms 8404 KB Output is correct
7 Correct 5 ms 8404 KB Output is correct
8 Correct 5 ms 8404 KB Output is correct
9 Correct 1056 ms 9080 KB Output is correct
10 Correct 5 ms 8404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 67148 KB Output is correct
2 Correct 67 ms 67152 KB Output is correct
3 Correct 76 ms 67148 KB Output is correct
4 Correct 92 ms 67948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 9208 KB Output is correct
2 Correct 229 ms 9100 KB Output is correct
3 Correct 221 ms 9044 KB Output is correct
4 Correct 202 ms 9088 KB Output is correct
5 Correct 238 ms 9084 KB Output is correct
6 Correct 62 ms 67148 KB Output is correct
7 Correct 72 ms 67148 KB Output is correct
8 Correct 74 ms 67132 KB Output is correct
9 Correct 91 ms 67916 KB Output is correct
10 Correct 54 ms 63252 KB Output is correct
11 Correct 57 ms 63240 KB Output is correct
12 Correct 123 ms 64776 KB Output is correct
13 Correct 70 ms 63244 KB Output is correct
14 Correct 52 ms 63188 KB Output is correct
15 Correct 5 ms 8404 KB Output is correct
16 Correct 5 ms 8404 KB Output is correct
17 Correct 5 ms 8404 KB Output is correct
18 Correct 5 ms 8404 KB Output is correct
19 Correct 4 ms 8412 KB Output is correct
20 Correct 5 ms 8404 KB Output is correct
21 Correct 4 ms 8404 KB Output is correct
22 Correct 5 ms 8404 KB Output is correct
23 Correct 5 ms 8404 KB Output is correct
24 Correct 5 ms 8404 KB Output is correct
25 Correct 73 ms 9484 KB Output is correct
26 Correct 5 ms 8404 KB Output is correct
27 Correct 1055 ms 9084 KB Output is correct
28 Correct 2190 ms 67452 KB Output is correct
29 Correct 2384 ms 44128 KB Output is correct
30 Correct 2408 ms 44020 KB Output is correct
31 Correct 2628 ms 68536 KB Output is correct
32 Correct 4 ms 8404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 9084 KB Output is correct
2 Correct 212 ms 9100 KB Output is correct
3 Correct 217 ms 9044 KB Output is correct
4 Correct 209 ms 9104 KB Output is correct
5 Correct 242 ms 8976 KB Output is correct
6 Correct 61 ms 67148 KB Output is correct
7 Correct 56 ms 67128 KB Output is correct
8 Correct 74 ms 67152 KB Output is correct
9 Correct 94 ms 67904 KB Output is correct
10 Correct 61 ms 63320 KB Output is correct
11 Correct 66 ms 63196 KB Output is correct
12 Correct 128 ms 64820 KB Output is correct
13 Correct 70 ms 63128 KB Output is correct
14 Correct 57 ms 63280 KB Output is correct
15 Correct 1785 ms 67132 KB Output is correct
16 Correct 10273 ms 68800 KB Output is correct
17 Correct 5 ms 8404 KB Output is correct
18 Correct 4 ms 8404 KB Output is correct
19 Correct 4 ms 8404 KB Output is correct
20 Correct 5 ms 8404 KB Output is correct
21 Correct 5 ms 8404 KB Output is correct
22 Correct 5 ms 8420 KB Output is correct
23 Correct 5 ms 8404 KB Output is correct
24 Correct 5 ms 8504 KB Output is correct
25 Correct 5 ms 8472 KB Output is correct
26 Correct 6 ms 8404 KB Output is correct
27 Correct 87 ms 9436 KB Output is correct
28 Correct 5 ms 8404 KB Output is correct
29 Correct 1020 ms 9084 KB Output is correct
30 Correct 2171 ms 67572 KB Output is correct
31 Correct 9172 ms 67940 KB Output is correct
32 Correct 10359 ms 67948 KB Output is correct
33 Correct 2349 ms 44192 KB Output is correct
34 Correct 9489 ms 44424 KB Output is correct
35 Correct 2519 ms 43972 KB Output is correct
36 Correct 9368 ms 44284 KB Output is correct
37 Correct 2670 ms 68432 KB Output is correct
38 Correct 9903 ms 68520 KB Output is correct
39 Correct 4 ms 8404 KB Output is correct
40 Correct 9891 ms 44588 KB Output is correct