//#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 = 20005;
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][100][100];
void merge(int cur) {
for (int i = 0; i < C; i++)
for (int j = 0; j < C; j++)
dp[cur][i][j] = INF;
for (int i = 0; i < C; i++) {
for (int j = 0; j < C; j++) {
for (int k = 0; k < C; k++) {
dp[cur][i][j] = min(dp[cur][i][j], dp[L[cur]][i][k] + dp[R[cur]][k][j]);
}
}
}
}
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 + 5 >= 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 + 5 >= 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 |
16512 KB |
Output is correct |
2 |
Correct |
16 ms |
16512 KB |
Output is correct |
3 |
Correct |
100 ms |
18040 KB |
Output is correct |
4 |
Correct |
14 ms |
16512 KB |
Output is correct |
5 |
Correct |
15 ms |
16512 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 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 |
3 ms |
512 KB |
Output is correct |
5 |
Correct |
3 ms |
512 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
87 ms |
1528 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
498 ms |
2192 KB |
Output is correct |
2 |
Correct |
683 ms |
2272 KB |
Output is correct |
3 |
Correct |
645 ms |
2296 KB |
Output is correct |
4 |
Correct |
533 ms |
2172 KB |
Output is correct |
5 |
Correct |
535 ms |
2168 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 |
9 |
Correct |
2522 ms |
2252 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
25088 KB |
Output is correct |
2 |
Correct |
30 ms |
25088 KB |
Output is correct |
3 |
Correct |
26 ms |
25088 KB |
Output is correct |
4 |
Correct |
58 ms |
25976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
498 ms |
2164 KB |
Output is correct |
2 |
Correct |
575 ms |
2168 KB |
Output is correct |
3 |
Correct |
573 ms |
2168 KB |
Output is correct |
4 |
Correct |
591 ms |
2296 KB |
Output is correct |
5 |
Correct |
609 ms |
2168 KB |
Output is correct |
6 |
Correct |
25 ms |
25088 KB |
Output is correct |
7 |
Correct |
23 ms |
25080 KB |
Output is correct |
8 |
Correct |
23 ms |
25216 KB |
Output is correct |
9 |
Correct |
59 ms |
25976 KB |
Output is correct |
10 |
Correct |
15 ms |
16512 KB |
Output is correct |
11 |
Correct |
14 ms |
16512 KB |
Output is correct |
12 |
Correct |
76 ms |
18040 KB |
Output is correct |
13 |
Correct |
16 ms |
16512 KB |
Output is correct |
14 |
Correct |
15 ms |
16512 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 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 |
512 KB |
Output is correct |
21 |
Correct |
3 ms |
512 KB |
Output is correct |
22 |
Correct |
2 ms |
512 KB |
Output is correct |
23 |
Correct |
3 ms |
512 KB |
Output is correct |
24 |
Correct |
3 ms |
512 KB |
Output is correct |
25 |
Correct |
74 ms |
1544 KB |
Output is correct |
26 |
Correct |
2 ms |
512 KB |
Output is correct |
27 |
Correct |
2646 ms |
2268 KB |
Output is correct |
28 |
Correct |
7278 ms |
96768 KB |
Output is correct |
29 |
Correct |
7212 ms |
97524 KB |
Output is correct |
30 |
Correct |
7130 ms |
97428 KB |
Output is correct |
31 |
Correct |
7479 ms |
101988 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
515 ms |
2196 KB |
Output is correct |
2 |
Correct |
550 ms |
2172 KB |
Output is correct |
3 |
Correct |
537 ms |
2168 KB |
Output is correct |
4 |
Correct |
556 ms |
2176 KB |
Output is correct |
5 |
Correct |
534 ms |
2256 KB |
Output is correct |
6 |
Correct |
23 ms |
25088 KB |
Output is correct |
7 |
Correct |
22 ms |
25088 KB |
Output is correct |
8 |
Correct |
24 ms |
25088 KB |
Output is correct |
9 |
Correct |
61 ms |
25976 KB |
Output is correct |
10 |
Correct |
16 ms |
16512 KB |
Output is correct |
11 |
Correct |
17 ms |
16512 KB |
Output is correct |
12 |
Correct |
98 ms |
18124 KB |
Output is correct |
13 |
Correct |
15 ms |
16512 KB |
Output is correct |
14 |
Correct |
16 ms |
16512 KB |
Output is correct |
15 |
Incorrect |
10622 ms |
96372 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |