This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#include "wombats.h"
#include <cstdio>
#include <set>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cassert>
using namespace std;
template <typename T>
using ve = vector<T>;
#ifndef ROW
#define ROW 5000
#endif
int r, c, h[ROW][100], v[ROW][100];
int ans_5[100][100];
void calc_sub5_dp() {
static int dp[2][100];
for (int ii = 0; ii < c; ++ii) {
/* find answer for (V1, V2) where V1 = ii */
memset(dp[0], 63, sizeof dp[0]);
dp[0][ii] = 0;
int I = 0;
for (int i = 0; i < r; ++i, I ^= 1) {
static int pre[100], suf[100], ph[100]; /* annoying ahh math */
ph[0] = 0;
for (int j = 0; j + 1 < c; ++j)
ph[j + 1] = ph[j] + h[i][j];
pre[0] = dp[I][0]; /* - ph[0] = 0; */
for (int j = 1; j < c; ++j) pre[j] = min(pre[j - 1], dp[I][j] - ph[j]);
suf[c - 1] = dp[I][c - 1] + ph[c - 1];
for (int j = c - 2; j >= 0; --j) suf[j] = min(suf[j + 1], dp[I][j] + ph[j]);
for (int j = 0; j < c; ++j) {
dp[I][j] = min({dp[I][j], ph[j] + pre[j], suf[j] - ph[j]});
if (i + 1 < r)
dp[!I][j] = dp[I][j] + v[i][j];
}
}
for (int jj = 0; jj < c; ++jj) ans_5[ii][jj] = dp[(r - 1) & 1][jj];
}
}
void changeH(int P, int Q, int W) {
h[P][Q] = W;
calc_sub5_dp();
}
void changeV(int P, int Q, int W) {
v[P][Q] = W;
calc_sub5_dp();
}
void init(int R, int C, int H[ROW][200], int V[ROW][200]) {
r = R, c = C;
for (int i = 0; i + 1 < r; ++i) for (int j = 0; j < c; ++j)
v[i][j] = V[i][j];
for (int i = 0 ; i < r; ++i) for (int j = 0; j + 1 < c; ++j)
h[i][j] = H[i][j];
calc_sub5_dp();
}
int escape(int V1, int V2) {
return ans_5[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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |