Submission #763446

# Submission time Handle Problem Language Result Execution time Memory
763446 2023-06-22T10:06:56 Z SanguineChameleon Wombats (IOI13_wombats) C++17
100 / 100
3256 ms 122504 KB
#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;

const int inf = 1e9 + 20;
const int maxN = 5e3 + 20;
const int maxM = 2e2 + 20;
const int block = 20;
int hor[maxN][maxM];
int ver[maxN][maxM];
int tmp[maxN][maxM];
int dp[maxN][maxM];
int opt[maxM][maxM];
int tree[maxN / block * 4][maxM][maxM];
int N, M;

void calc(int id, int lt, int rt) {
	for (int X = 0; X < M; X++) {
		dp[lt][X] = 0;
		for (int i = X - 1; i >= 0; i--) {
			dp[lt][i] = dp[lt][i + 1] + hor[lt][i];
		}
		for (int i = X + 1; i < M; i++) {
			dp[lt][i] = dp[lt][i - 1] + hor[lt][i - 1];
		}
		for (int i = lt + 1; i <= rt; i++) {
			for (int j = 0; j < M; j++) {
				tmp[i][j] = dp[i - 1][j] + ver[i - 1][j];
				dp[i][j] = tmp[i][j];
			}
			int best = tmp[i][0];
			for (int j = 1; j < M; j++) {
				best = min(best + hor[i][j - 1], tmp[i][j]);
				dp[i][j] = min(dp[i][j], best);
			}
			best = tmp[i][M - 1];
			for (int j = M - 2; j >= 0; j--) {
				best = min(best + hor[i][j], tmp[i][j]);
				dp[i][j] = min(dp[i][j], best);
			}
		}
		for (int Y = 0; Y < M; Y++) {
			tree[id][X][Y] = dp[rt][Y];
		}
	}
}

void merge(int id, int mt) {
	for (int X = 0; X < M; X++) {
		for (int Y = 0; Y < M; Y++) {
			tree[id][X][Y] = inf;
		}
	}
	for (int X = 0; X < M; X++) {
		for (int Z = (X > 0 ? opt[X - 1][X - 1] : 0); Z < M; Z++) {
			int cur = tree[id * 2][X][Z] + ver[mt][Z] + tree[id * 2 + 1][Z][X];
			if (cur < tree[id][X][X]) {
				tree[id][X][X] = cur;
				opt[X][X] = Z;
			}
		}
	}
	for (int diff = 1; diff < M; diff++) {
		for (int X = 0, Y = diff; Y < M; X++, Y++) {
			for (int Z = opt[X][Y - 1]; Z <= opt[X + 1][Y]; Z++) {
				int cur = tree[id * 2][X][Z] + ver[mt][Z] + tree[id * 2 + 1][Z][Y];
				if (cur < tree[id][X][Y]) {
					tree[id][X][Y] = cur;
					opt[X][Y] = Z;
				}
			}
		}
		for (int X = diff, Y = 0; X < M; X++, Y++) {
			for (int Z = opt[X - 1][Y]; Z <= opt[X][Y + 1]; Z++) {
				int cur = tree[id * 2][X][Z] + ver[mt][Z] + tree[id * 2 + 1][Z][Y];
				if (cur < tree[id][X][Y]) {
					tree[id][X][Y] = cur;
					opt[X][Y] = Z;
				}
			}
		}
	}
}

void build(int id, int lt, int rt) {
	if (lt == rt) {
		calc(id, lt * block, min(N - 1, lt * block + block - 1));
		return;
	}
	int mt = (lt + rt) / 2;
	build(id * 2, lt, mt);
	build(id * 2 + 1, mt + 1, rt);
	merge(id, mt * block + block - 1);
}

void update(int id, int lt, int rt, int pos) {
	if (lt == rt) {
		calc(id, lt * block, min(N - 1, lt * block + block - 1));
		return;
	}
	int mt = (lt + rt) / 2;
	if (pos <= mt) {
		update(id * 2, lt, mt, pos);
	}
	else {
		update(id * 2 + 1, mt + 1, rt, pos);
	}
	merge(id, mt * block + block - 1);
}

void init(int R, int C, int H[5000][200], int V[5000][200]) {
	N = R;
	M = C;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M - 1; j++) {
			hor[i][j] = H[i][j];
		}
	}
	for (int i = 0; i < N - 1; i++) {
		for (int j = 0; j < M; j++) {
			ver[i][j] = V[i][j];
		}
	}
	build(1, 0, (N - 1) / block);
}

void changeH(int P, int Q, int W) {
	hor[P][Q] = W;
	update(1, 0, (N - 1) / block, P / block);
}

void changeV(int P, int Q, int W) {
	ver[P][Q] = W;
	update(1, 0, (N - 1) / block, P / block);
}

int escape(int X, int Y) {
	return tree[1][X][Y];
}

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;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 19284 KB Output is correct
2 Correct 9 ms 19264 KB Output is correct
3 Correct 67 ms 22088 KB Output is correct
4 Correct 10 ms 19284 KB Output is correct
5 Correct 12 ms 19268 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 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 436 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 444 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 56 ms 2780 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 1816 KB Output is correct
2 Correct 87 ms 1748 KB Output is correct
3 Correct 91 ms 1804 KB Output is correct
4 Correct 99 ms 1804 KB Output is correct
5 Correct 103 ms 1800 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 308 KB Output is correct
9 Correct 423 ms 1804 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 27964 KB Output is correct
2 Correct 12 ms 28004 KB Output is correct
3 Correct 14 ms 28000 KB Output is correct
4 Correct 42 ms 29364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 1808 KB Output is correct
2 Correct 86 ms 1784 KB Output is correct
3 Correct 91 ms 1812 KB Output is correct
4 Correct 90 ms 1724 KB Output is correct
5 Correct 97 ms 1800 KB Output is correct
6 Correct 14 ms 27988 KB Output is correct
7 Correct 15 ms 27936 KB Output is correct
8 Correct 13 ms 27988 KB Output is correct
9 Correct 41 ms 29524 KB Output is correct
10 Correct 10 ms 19284 KB Output is correct
11 Correct 9 ms 19372 KB Output is correct
12 Correct 67 ms 22020 KB Output is correct
13 Correct 9 ms 19316 KB Output is correct
14 Correct 8 ms 19284 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 436 KB Output is correct
19 Correct 1 ms 444 KB Output is correct
20 Correct 1 ms 440 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 56 ms 2728 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 413 ms 1800 KB Output is correct
28 Correct 778 ms 74324 KB Output is correct
29 Correct 808 ms 61440 KB Output is correct
30 Correct 873 ms 61452 KB Output is correct
31 Correct 842 ms 76080 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 1808 KB Output is correct
2 Correct 92 ms 1792 KB Output is correct
3 Correct 95 ms 1808 KB Output is correct
4 Correct 93 ms 1808 KB Output is correct
5 Correct 93 ms 1800 KB Output is correct
6 Correct 15 ms 28092 KB Output is correct
7 Correct 12 ms 27968 KB Output is correct
8 Correct 13 ms 27952 KB Output is correct
9 Correct 39 ms 29364 KB Output is correct
10 Correct 10 ms 19284 KB Output is correct
11 Correct 11 ms 19288 KB Output is correct
12 Correct 62 ms 22020 KB Output is correct
13 Correct 9 ms 19284 KB Output is correct
14 Correct 7 ms 19284 KB Output is correct
15 Correct 942 ms 117064 KB Output is correct
16 Correct 3256 ms 120376 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 436 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 56 ms 2764 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 417 ms 1800 KB Output is correct
30 Correct 790 ms 74604 KB Output is correct
31 Correct 2945 ms 121828 KB Output is correct
32 Correct 2929 ms 121820 KB Output is correct
33 Correct 799 ms 61488 KB Output is correct
34 Correct 2940 ms 100920 KB Output is correct
35 Correct 824 ms 61636 KB Output is correct
36 Correct 3008 ms 100900 KB Output is correct
37 Correct 803 ms 76076 KB Output is correct
38 Correct 2939 ms 122504 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 3173 ms 101252 KB Output is correct