// ~ Be Name Khoda ~ //
#include "wombats.h"
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops,Ofast")
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
const int maxnR = 5002;
const int maxnt = 700;
const int maxnC = 202;
const int mod = 2e9;
const int lim = 9;
int n, m, h[maxnR][maxnC], v[maxnR][maxnC], chil[maxnt][2];
int dp[2][maxnC][maxnC], opt[maxnC][maxnC], newnode = 1;
struct __dp{
int dp[maxnC][maxnC];
} seg[maxnt];
inline void comb(__dp *ret, int mid, const __dp &a, const __dp &b){
for(int dim = -(m - 1); dim < m; dim++) for(int i = max(0, -dim); i < min(m, m - dim); i++){
int j = dim + i;
int l = (j ? opt[i][j - 1] : 0), r = (i + 1 < m ? opt[i + 1][j] : m - 1);
ret->dp[i][j] = mod;
for(int k = l; k <= r; k++){
int val = a.dp[i][k] + b.dp[k][j] + v[mid - 1][k];
if(val < ret->dp[i][j]){
opt[i][j] = k;
ret->dp[i][j] = val;
}
}
}
}
inline void cre(__dp *a, int l, int r){
for(int i = 0; i < m; i++) for(int j = 0; j < m; j++)
dp[(l + 1) & 1][i][j] = mod;
for(int i = 0; i < m; i++)
dp[(l + 1) & 1][i][i] = 0;
for(int j = l; j < r; j++) for(int x = 0; x < m; x++){
int mn = mod;
for(int i = 0; i < m; i++){
dp[j & 1][x][i] = min(mn, dp[(j + 1) & 1][x][i] + (j > l ? v[j - 1][i] : 0));
mn = dp[j & 1][x][i] + h[j][i];
}
mn = mod;
for(int i = m - 1; i >= 0; i--){
dp[j & 1][x][i] = min(mn, dp[j & 1][x][i]);
if(i)
mn = dp[j & 1][x][i] + h[j][i - 1];
//cout << "check " << j << ' ' << x << ' ' << i << ' ' << dp[j & 1][x][i] << ' ' << mn << endl;
}
}
for(int i = 0; i < m; i++) for(int j = 0; j < m; j++)
a->dp[i][j] = dp[(r - 1) & 1][i][j];
}
void upd(int l, int r, int id, int v){
int mid = (l + r) >> 1;
if(id < mid && chil[v][0])
upd(l, mid, id, chil[v][0]);
if(id >= mid && chil[v][1])
upd(mid, r, id, chil[v][1]);
if(chil[v][0] && chil[v][1])
comb(&seg[v], mid, seg[chil[v][0]], seg[chil[v][1]]);
else
cre(&seg[v], l, r);
}
int build(int l, int r){
if(r - l != n && r - l <= lim)
return 0;
int v = newnode++;
assert(newnode < maxnt);
int mid = (l + r) >> 1;
chil[v][0] = build(l, mid);
chil[v][1] = build(mid, r);
if(chil[v][0] && chil[v][1])
comb(&seg[v], mid, seg[chil[v][0]], seg[chil[v][1]]);
else
cre(&seg[v], l, r);
return v;
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
n = R;
m = C;
ll sum = 0;
for(int i = 0; i < n; i++) for(int j = 0; j < m; j++){
h[i][j] = H[i][j];
v[i][j] = V[i][j];
sum += v[i][0];
}
build(0, n);
}
void changeH(int p, int q, int w) {
h[p][q] = w;
upd(0, n, p, 1);
}
void changeV(int p, int q, int w) {
v[p][q] = w;
upd(0, n, p, 1);
}
int escape(int v1, int v2) {
return seg[1].dp[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;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
31 ms |
30548 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
440 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
61 ms |
2764 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
2220 KB |
Output is correct |
2 |
Correct |
47 ms |
2176 KB |
Output is correct |
3 |
Correct |
56 ms |
2132 KB |
Output is correct |
4 |
Correct |
56 ms |
2132 KB |
Output is correct |
5 |
Correct |
55 ms |
2184 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
236 ms |
2200 KB |
Output is correct |
10 |
Correct |
1 ms |
304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
35 ms |
39504 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
2200 KB |
Output is correct |
2 |
Correct |
47 ms |
2168 KB |
Output is correct |
3 |
Correct |
59 ms |
2208 KB |
Output is correct |
4 |
Correct |
61 ms |
2212 KB |
Output is correct |
5 |
Correct |
55 ms |
2132 KB |
Output is correct |
6 |
Runtime error |
35 ms |
39604 KB |
Execution killed with signal 6 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
2216 KB |
Output is correct |
2 |
Correct |
47 ms |
2136 KB |
Output is correct |
3 |
Correct |
57 ms |
2132 KB |
Output is correct |
4 |
Correct |
56 ms |
2112 KB |
Output is correct |
5 |
Correct |
55 ms |
2188 KB |
Output is correct |
6 |
Runtime error |
33 ms |
39584 KB |
Execution killed with signal 6 |
7 |
Halted |
0 ms |
0 KB |
- |