답안 #680028

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
680028 2023-01-09T19:40:11 Z bashkort 웜뱃 (IOI13_wombats) C++17
28 / 100
1255 ms 27988 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 = 200, R = 5000, C = 200, K = (R + B - 1) / B;
constexpr int N = K * 4;

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


void pull(int x) {
    if (lx[x << 1 | 1] == -1) {
        lx[x] = lx[x << 1], rx[x] = rx[x << 1];
        memcpy(dp[x], dp[x << 1], sizeof(dp[x]));
        return;
    }
    memset(dp[x], 0x3f, sizeof(dp[x]));
    for (int a = 0; a < c; ++a) {
        function<void(int, int, int, int)> solve = [&](int l, int r, int optl, int optr) {
            if (l >= r) {
                return;
            }

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

            int opt = optl;

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

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

void update_fr(int L) {
    memset(fr[L], 0x3f, sizeof(fr[L]));
    for (int a = 0; a < c; ++a) {
        fr[L][a][a] = 0;
    }
    int lim = max(0, B * L);
    for (int i = min(r, B * (L + 1)) - 1; i >= lim; --i) {
        for (int a = 0; a < c - 1; ++a) {
            for (int cc = 0; cc < c; ++cc) {
                ckmin(fr[L][a + 1][cc], fr[L][a][cc] + H[i][a]);
            }
        }
        for (int a = c - 2; a >= 0; --a) {
            for (int cc = 0; cc < c; ++cc) {
                ckmin(fr[L][a][cc], fr[L][a + 1][cc] + H[i][a]);
            }
        }
        if (i != lim) {
            for (int cc = 0; cc < c; ++cc) {
                for (int a = 0; a < c; ++a) {
                    fr[L][a][cc] += V[i - 1][a];
                }
            }
        }
    }
    memcpy(dp[sz + L], fr[L], sizeof(dp[sz + L]));
    lx[sz + L] = B * L, rx[sz + L] = min(r - 1, (L + 1) * B - 1);

    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));
    memset(lx, -1, sizeof(lx)), memset(rx, -1, sizeof(rx));

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

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

    int L = P / B;

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

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

    int L = (P + 1) / B;

    if ((P + 1) % B != 0) {
        update_fr(L);
    }
}

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:86:26: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   86 |     sz = 1 << __lg(need) + bool(need & (need - 1));
      |               ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 24116 KB Output is correct
2 Incorrect 27 ms 24120 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8404 KB Output is correct
2 Correct 5 ms 8404 KB Output is correct
3 Correct 4 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 5 ms 8404 KB Output is correct
7 Correct 4 ms 8404 KB Output is correct
8 Correct 4 ms 8404 KB Output is correct
9 Correct 5 ms 8444 KB Output is correct
10 Correct 5 ms 8404 KB Output is correct
11 Correct 67 ms 9444 KB Output is correct
12 Correct 5 ms 8424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 313 ms 8616 KB Output is correct
2 Correct 258 ms 8616 KB Output is correct
3 Correct 289 ms 8616 KB Output is correct
4 Correct 302 ms 8620 KB Output is correct
5 Correct 302 ms 8620 KB Output is correct
6 Correct 5 ms 8384 KB Output is correct
7 Correct 4 ms 8404 KB Output is correct
8 Correct 4 ms 8404 KB Output is correct
9 Correct 1255 ms 8632 KB Output is correct
10 Correct 4 ms 8404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 27940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 289 ms 8616 KB Output is correct
2 Correct 288 ms 8616 KB Output is correct
3 Correct 287 ms 8532 KB Output is correct
4 Correct 301 ms 8616 KB Output is correct
5 Correct 290 ms 8532 KB Output is correct
6 Incorrect 36 ms 27988 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 287 ms 8616 KB Output is correct
2 Correct 261 ms 8632 KB Output is correct
3 Correct 289 ms 8532 KB Output is correct
4 Correct 294 ms 8612 KB Output is correct
5 Correct 281 ms 8616 KB Output is correct
6 Incorrect 28 ms 27976 KB Output isn't correct
7 Halted 0 ms 0 KB -