Submission #679954

# Submission time Handle Problem Language Result Execution time Memory
679954 2023-01-09T16:55:39 Z bashkort Wombats (IOI13_wombats) C++17
28 / 100
7885 ms 262144 KB
#include <bits/stdc++.h>
#include "wombats.h"

using namespace std;

inline void ckmin(int &a, int b) {
    if (a > b) a = b;
}

constexpr int B = 1, R = 5000, C = 200, K = (R + B - 1) / B;

int r, c, need;
int dp[K][C][C], fr[K][C][C], H[R][C], V[R][C];

void update_dp(int L) {
    if (L == need - 1) {
        memcpy(dp[L], fr[L], sizeof(dp[L]));
        return;
    }
    memset(dp[L], 0x3f, sizeof(dp[L]));
    for (int a = 0; a < c; ++a) {
        for (int b = 0; b < c; ++b) {
            for (int cc = 0; cc < c; ++cc) {
                ckmin(dp[L][a][cc], fr[L][a][b] + V[(L + 1) * B - 1][b] + dp[L + 1][b][cc]);
            }
        }
    }
}

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 = B * L;
    for (int i = min(r, B * (L + 1)) - 1; i >= lim; --i) {
        for (int cc = 0; cc < c; ++cc) {
            for (int a = 0; a < c - 1; ++a) {
                ckmin(fr[L][a + 1][cc], fr[L][a][cc] + H[i][a]);
            }
            for (int a = c - 2; a >= 0; --a) {
                ckmin(fr[L][a][cc], fr[L][a + 1][cc] + H[i][a]);
            }
            if (i != lim) {
                for (int a = 0; a < c; ++a) {
                    fr[L][a][cc] += V[i - 1][a];
                }
            }
        }
    }
}

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) / B;
    for (int i = need - 1; i >= 0; --i) {
        update_fr(i);
    }
    for (int i = need - 1; i >= 0; --i) {
        update_dp(i);
    }
}

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

    int L = P / B;

    update_fr(L);

    if (L == need - 1) {
        memcpy(dp[L], fr[L], sizeof(dp[L]));
    } else {
        update_dp(L);
    }
    for (int i = L - 1; i >= 0; --i) {
        update_dp(i);
    }
}

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

    int L = P / B;

    if ((P + 1) % B != 0) {
        update_fr(L);
    }
    for (int i = L; i >= 0; --i) {
        update_dp(i);
    }
}

int escape(int V1, int V2) {
    return dp[0][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 Runtime error 118 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8788 KB Output is correct
2 Correct 5 ms 8788 KB Output is correct
3 Correct 5 ms 8696 KB Output is correct
4 Correct 6 ms 14420 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 8 ms 14420 KB Output is correct
7 Correct 10 ms 14412 KB Output is correct
8 Correct 10 ms 14036 KB Output is correct
9 Correct 8 ms 14064 KB Output is correct
10 Correct 8 ms 14400 KB Output is correct
11 Correct 85 ms 16704 KB Output is correct
12 Correct 7 ms 14376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7507 ms 39300 KB Output is correct
2 Correct 1072 ms 39388 KB Output is correct
3 Correct 3880 ms 39688 KB Output is correct
4 Correct 4620 ms 39772 KB Output is correct
5 Correct 1135 ms 39700 KB Output is correct
6 Correct 5 ms 8788 KB Output is correct
7 Correct 6 ms 8788 KB Output is correct
8 Correct 5 ms 8784 KB Output is correct
9 Correct 5855 ms 39688 KB Output is correct
10 Correct 5 ms 9044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 95 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7437 ms 39304 KB Output is correct
2 Correct 1068 ms 39376 KB Output is correct
3 Correct 3920 ms 39696 KB Output is correct
4 Correct 4626 ms 39692 KB Output is correct
5 Correct 1214 ms 39692 KB Output is correct
6 Runtime error 95 ms 262144 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7885 ms 39312 KB Output is correct
2 Correct 1073 ms 39500 KB Output is correct
3 Correct 4080 ms 39756 KB Output is correct
4 Correct 5073 ms 39692 KB Output is correct
5 Correct 1207 ms 39696 KB Output is correct
6 Runtime error 101 ms 262144 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -