//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include "wombats.h"
//#include "grader.h"
using namespace std;
typedef long long int ll;
const int INF = 1e9 + 7;
const int MAXN = 2005;
const double eps = 1e-9;
int RW, C, root = 0, segSz = 1;
int h[5000][200], v[5000][200], L[MAXN], R[MAXN];
int dp[MAXN][200][200], opt[200];
void merge(int cur) {
for (int i = 0; i < C; i++) {
opt[i] = 0;
for (int j = 0; j < C; j++)
dp[cur][i][j] = INF;
}
for (int i = C - 1; i > -C; i--) {
for (int j = C + min(-i, 0) - 1; j >= max(-i, 0); j--) {
int oL = 0, oR = C - 1;
if (j != max(-i, 0))
oL = opt[j - 1];
if (j != C + min(-i, 0) - 1)
oR = opt[j];
for (int k = oL; k <= oR; k++) {
if (dp[cur][j][i + j] > dp[L[cur]][j][k] + dp[R[cur]][k][i + j]) {
dp[cur][j][i + j] = dp[L[cur]][j][k] + dp[R[cur]][k][i + j];
opt[j] = k;
}
}
}
}
}
void init(int cur, int l, int r) {
for (int i = 0; i < C; i++) {
for (int j = 0; j < C; j++)
dp[cur][i][j] = INF;
dp[cur][i][i] = 0;
}
for (int k = l; k <= r; k++) {
for (int i = 0; i < C; i++) {
for (int j = 1; j < C; j++)
dp[cur][i][j] = min(dp[cur][i][j], dp[cur][i][j - 1] + h[k][j - 1]);
for (int j = C - 2; j > -1; j--)
dp[cur][i][j] = min(dp[cur][i][j], dp[cur][i][j + 1] + h[k][j]);
}
for (int i = 0; i < C; i++)
for (int j = 0; j < C; j++)
dp[cur][i][j] += v[k][j];
}
}
void upd(int l, int r, int cur, int ind) {
if (l + 10 >= r) {
init(cur, l, r);
return;
}
int m = (l + r) / 2;
if (ind <= m) upd(l, m, L[cur], ind);
else upd(m + 1, r, R[cur], ind);
merge(cur);
}
void build(int l, int r, int &cur) {
cur = segSz++;
if (l + 10 >= r) {
init(cur, l, r);
return;
}
int m = (l + r) / 2;
build(l, m, L[cur]);
build(m + 1, r, R[cur]);
merge(cur);
}
void init(int R1, int C1, int H[5000][200], int V[5000][200]) {
RW = R1, C = C1;
for (int i = 0; i < RW; i++)
for (int j = 0; j + 1 < C; j++)
h[i][j] = H[i][j];
for (int i = 0; i + 1 < RW; i++)
for (int j = 0; j < C; j++)
v[i][j] = V[i][j];
build(0, RW - 1, root);
}
void changeH(int p, int q, int w) {
h[p][q] = w;
upd(0, RW - 1, root, p);
}
void changeV(int p, int q, int w) {
v[p][q] = w;
upd(0, RW - 1, root, p);
}
int escape(int a, int b) {
return dp[root][a][b];
}
Compilation message
grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
int res;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
12544 KB |
Output is correct |
2 |
Correct |
13 ms |
12544 KB |
Output is correct |
3 |
Correct |
80 ms |
14144 KB |
Output is correct |
4 |
Correct |
12 ms |
12620 KB |
Output is correct |
5 |
Correct |
15 ms |
12544 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
3 ms |
512 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
76 ms |
1528 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
109 ms |
3320 KB |
Output is correct |
2 |
Correct |
100 ms |
3300 KB |
Output is correct |
3 |
Correct |
108 ms |
3268 KB |
Output is correct |
4 |
Correct |
110 ms |
3200 KB |
Output is correct |
5 |
Correct |
101 ms |
3244 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
401 ms |
3200 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
21120 KB |
Output is correct |
2 |
Correct |
20 ms |
21120 KB |
Output is correct |
3 |
Correct |
20 ms |
21164 KB |
Output is correct |
4 |
Correct |
51 ms |
21984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
105 ms |
3200 KB |
Output is correct |
2 |
Correct |
91 ms |
3200 KB |
Output is correct |
3 |
Correct |
113 ms |
3200 KB |
Output is correct |
4 |
Correct |
120 ms |
3200 KB |
Output is correct |
5 |
Correct |
105 ms |
3200 KB |
Output is correct |
6 |
Correct |
21 ms |
21240 KB |
Output is correct |
7 |
Correct |
19 ms |
21120 KB |
Output is correct |
8 |
Correct |
23 ms |
21180 KB |
Output is correct |
9 |
Correct |
88 ms |
21972 KB |
Output is correct |
10 |
Correct |
15 ms |
12544 KB |
Output is correct |
11 |
Correct |
13 ms |
12544 KB |
Output is correct |
12 |
Correct |
78 ms |
14164 KB |
Output is correct |
13 |
Correct |
15 ms |
12544 KB |
Output is correct |
14 |
Correct |
12 ms |
12544 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
19 |
Correct |
2 ms |
512 KB |
Output is correct |
20 |
Correct |
2 ms |
508 KB |
Output is correct |
21 |
Correct |
2 ms |
512 KB |
Output is correct |
22 |
Correct |
2 ms |
512 KB |
Output is correct |
23 |
Correct |
2 ms |
512 KB |
Output is correct |
24 |
Correct |
3 ms |
512 KB |
Output is correct |
25 |
Correct |
68 ms |
1404 KB |
Output is correct |
26 |
Correct |
3 ms |
512 KB |
Output is correct |
27 |
Correct |
408 ms |
3292 KB |
Output is correct |
28 |
Correct |
1433 ms |
100472 KB |
Output is correct |
29 |
Correct |
1376 ms |
97704 KB |
Output is correct |
30 |
Correct |
1381 ms |
97656 KB |
Output is correct |
31 |
Correct |
1488 ms |
101440 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
108 ms |
3200 KB |
Output is correct |
2 |
Correct |
87 ms |
3200 KB |
Output is correct |
3 |
Correct |
110 ms |
3200 KB |
Output is correct |
4 |
Correct |
113 ms |
3200 KB |
Output is correct |
5 |
Correct |
97 ms |
3252 KB |
Output is correct |
6 |
Correct |
22 ms |
21248 KB |
Output is correct |
7 |
Correct |
19 ms |
21120 KB |
Output is correct |
8 |
Correct |
20 ms |
21248 KB |
Output is correct |
9 |
Correct |
55 ms |
22012 KB |
Output is correct |
10 |
Correct |
11 ms |
12544 KB |
Output is correct |
11 |
Correct |
13 ms |
12544 KB |
Output is correct |
12 |
Correct |
85 ms |
14072 KB |
Output is correct |
13 |
Correct |
15 ms |
12544 KB |
Output is correct |
14 |
Correct |
13 ms |
12544 KB |
Output is correct |
15 |
Correct |
1861 ms |
176248 KB |
Output is correct |
16 |
Correct |
5524 ms |
178804 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
412 KB |
Output is correct |
21 |
Correct |
4 ms |
512 KB |
Output is correct |
22 |
Correct |
2 ms |
432 KB |
Output is correct |
23 |
Correct |
3 ms |
512 KB |
Output is correct |
24 |
Correct |
2 ms |
512 KB |
Output is correct |
25 |
Correct |
2 ms |
512 KB |
Output is correct |
26 |
Correct |
2 ms |
512 KB |
Output is correct |
27 |
Correct |
74 ms |
2840 KB |
Output is correct |
28 |
Correct |
2 ms |
512 KB |
Output is correct |
29 |
Correct |
539 ms |
3404 KB |
Output is correct |
30 |
Correct |
1407 ms |
104288 KB |
Output is correct |
31 |
Correct |
5093 ms |
184688 KB |
Output is correct |
32 |
Correct |
5210 ms |
184756 KB |
Output is correct |
33 |
Correct |
1285 ms |
101172 KB |
Output is correct |
34 |
Correct |
4759 ms |
181456 KB |
Output is correct |
35 |
Correct |
1341 ms |
100988 KB |
Output is correct |
36 |
Correct |
4863 ms |
181352 KB |
Output is correct |
37 |
Correct |
1495 ms |
105996 KB |
Output is correct |
38 |
Correct |
5219 ms |
185328 KB |
Output is correct |
39 |
Correct |
2 ms |
376 KB |
Output is correct |
40 |
Correct |
5259 ms |
181428 KB |
Output is correct |