Submission #104924

# Submission time Handle Problem Language Result Execution time Memory
104924 2019-04-09T18:43:21 Z eriksuenderhauf Wombats (IOI13_wombats) C++11
55 / 100
20000 ms 24188 KB
//#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 = 4005;
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 <= r + 5) {
		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 <= r + 5) {
		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;
      ^~~
# Verdict Execution time Memory Grader output
1 Correct 33 ms 8192 KB Output is correct
2 Correct 22 ms 8192 KB Output is correct
3 Correct 93 ms 9720 KB Output is correct
4 Correct 21 ms 8320 KB Output is correct
5 Correct 22 ms 8192 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
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 480 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 72 ms 1400 KB Output is correct
12 Correct 3 ms 540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 672 ms 896 KB Output is correct
2 Correct 661 ms 888 KB Output is correct
3 Correct 663 ms 988 KB Output is correct
4 Correct 679 ms 784 KB Output is correct
5 Correct 664 ms 768 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 3438 ms 860 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 16076 KB Output is correct
2 Correct 82 ms 16124 KB Output is correct
3 Correct 79 ms 16024 KB Output is correct
4 Correct 114 ms 16760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 726 ms 812 KB Output is correct
2 Correct 648 ms 768 KB Output is correct
3 Correct 684 ms 860 KB Output is correct
4 Correct 667 ms 784 KB Output is correct
5 Correct 663 ms 888 KB Output is correct
6 Correct 77 ms 16000 KB Output is correct
7 Correct 72 ms 16000 KB Output is correct
8 Correct 83 ms 16148 KB Output is correct
9 Correct 121 ms 16740 KB Output is correct
10 Correct 20 ms 8192 KB Output is correct
11 Correct 20 ms 8192 KB Output is correct
12 Correct 86 ms 9732 KB Output is correct
13 Correct 22 ms 8192 KB Output is correct
14 Correct 23 ms 8192 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 3 ms 384 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 70 ms 1484 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 3308 ms 860 KB Output is correct
28 Execution timed out 20042 ms 16240 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 690 ms 788 KB Output is correct
2 Correct 646 ms 768 KB Output is correct
3 Correct 662 ms 768 KB Output is correct
4 Correct 644 ms 768 KB Output is correct
5 Correct 632 ms 768 KB Output is correct
6 Correct 65 ms 16000 KB Output is correct
7 Correct 65 ms 16024 KB Output is correct
8 Correct 81 ms 16000 KB Output is correct
9 Correct 119 ms 16820 KB Output is correct
10 Correct 22 ms 8192 KB Output is correct
11 Correct 22 ms 8192 KB Output is correct
12 Correct 80 ms 9800 KB Output is correct
13 Correct 21 ms 8164 KB Output is correct
14 Correct 22 ms 8192 KB Output is correct
15 Correct 6868 ms 16376 KB Output is correct
16 Execution timed out 20099 ms 24188 KB Time limit exceeded
17 Halted 0 ms 0 KB -