Submission #765100

#TimeUsernameProblemLanguageResultExecution timeMemory
765100Sohsoh84Wombats (IOI13_wombats)C++17
55 / 100
20048 ms262144 KiB
#include "wombats.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define X first #define Y second #define sep ' ' #define debug(x) cerr << #x << ": " << x << endl; const ll MAXN = 5000 + 10; const ll MAXM = 100 + 10; int n, m, H[MAXN][MAXM], V[MAXN][MAXM], ps[MAXN][MAXM], sg[MAXN << 2][MAXM][MAXM], opt[MAXM][MAXM]; inline void update_ps(int i) { for (int j = 2; j <= m; j++) ps[i][j] = ps[i][j - 1] + H[i][j - 1]; } inline void update_ans(int mid, int v) { for (int x = 1; x <= m; x++) { for (int y = 1; y <= m; y++) { sg[v][x][y] = sg[v << 1][x][x] + V[mid][x] + sg[v << 1 | 1][x][y]; for (int f = 1; f <= m; f++) { sg[v][x][y] = min(sg[v][x][y], sg[v << 1][x][f] + V[mid][f] + sg[v << 1 | 1][f][y]); } } } } void build(int l = 1, int r = n, int v = 1) { if (l == r) { for (int i = 1; i <= m; i++) for (int j = 1; j <= m; j++) sg[v][i][j] = ps[l][max(i, j)] - ps[l][min(i, j)]; } else { int mid = (l + r) >> 1; build(l, mid, v << 1); build(mid + 1, r, v << 1 | 1); update_ans(mid, v); } } void update(int ind, int l = 1, int r = n, int v = 1) { if (l == r) { for (int i = 1; i <= m; i++) for (int j = 1; j <= m; j++) sg[v][i][j] = ps[l][max(i, j)] - ps[l][min(i, j)]; } else { int mid = (l + r) >> 1; if (ind <= mid) update(ind, l, mid, v << 1); else update(ind, mid + 1, r, v << 1 | 1); update_ans(mid, v); } } void init(int R_, int C_, int H_[5000][200], int V_[5000][200]) { n = R_, m = C_; for (int i = 1; i <= n; i++) for (int j = 1; j < m; j++) H[i][j] = H_[i - 1][j - 1]; for (int i = 1; i < n; i++) for (int j = 1; j <= m; j++) V[i][j] = V_[i - 1][j - 1]; for (int i = 1; i <= n; i++) update_ps(i); build(); } void changeH(int P, int Q, int W) { P++, Q++; H[P][Q] = W; update_ps(P); update(P); } void changeV(int P, int Q, int W) { P++, Q++; V[P][Q] = W; update(P); } int escape(int V1, int V2) { V1++, V2++; return sg[1][V1][V2]; } // TODO: 1-base // TODO: check fit in ll // TODO: change max limits // TODO: check n == 1 // TODO: check bounds(n / m)

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...