Submission #679996

#TimeUsernameProblemLanguageResultExecution timeMemory
679996bashkortWombats (IOI13_wombats)C++17
76 / 100
20055 ms40116 KiB
#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; 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 cc = 0; cc < c; ++cc) { const int idx = (L + 1) * B - 1; 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[L][mid][cc], fr[L][mid][b] + V[idx][b] + dp[L + 1][b][cc])) { 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 = 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]; } } } } } 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 (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;
      |      ^~~
#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...