Submission #437455

# Submission time Handle Problem Language Result Execution time Memory
437455 2021-06-26T10:42:35 Z Eric_hoo Wombats (IOI13_wombats) C++14
100 / 100
6573 ms 175792 KB
#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;

const int INF = 2000000000;

int A[5000][200], B[5000][200];
int dp[10][200][200];
int cho[200][200];
int n, m;
int tmp[200][200];

void Merge(int f[200][200], int g[200][200], int wei[200], int h[200][200]) {
	for (int i = m - 1; i >= 0; i--) {
		for (int j = 0; j < m; j++) {
			int r = i + 1 < m ? cho[i + 1][j] : m - 1, l = j ? cho[i][j - 1] : 0;
			tmp[i][j] = INF;
			for (int k = l; k <= r; k++) {
				if (tmp[i][j] > f[i][k] + wei[k] + g[k][j]) {
					tmp[i][j] = f[i][k] + wei[k] + g[k][j];
					cho[i][j] = k;
				}
			}
		}
	}
	for (int i = 0; i < m; i++) for (int j = 0; j < m; j++) h[i][j] = tmp[i][j];
}

struct Segment_tree {
	int T[1024][200][200];
	void Calc(int now, int l, int r) {
		int W = min(10, n - l * 10);
		for (int i = 0; i < W; i++) {
			for (int j = 0; j < m; j++) {
				dp[i][j][j] = 0;
				for (int k = j - 1; k >= 0; k--) dp[i][j][k] = dp[i][j][k + 1] + A[l * 10 + i][k];
				for (int k = j + 1; k < m; k++) dp[i][j][k] = dp[i][j][k - 1] + A[l * 10 + i][k - 1];
			}
		}
		for (int j = 0; j < m; j++) for (int k = 0; k < m; k++) T[now][j][k] = dp[0][j][k];
		for (int i = 1; i < W; i++) Merge(T[now], dp[i], B[l * 10 + i - 1], T[now]);
	}
	void pushup(int now, int mid) {
		Merge(T[now << 1], T[now << 1 | 1], B[mid * 10 + 9], T[now]);
	}
	void Build(int now, int l, int r) {
		if (l == r) {
			Calc(now, l, r);
			return ;
		}
		int mid = l + r >> 1;
		Build(now << 1, l, mid), Build(now << 1 | 1, mid + 1, r);
		pushup(now, mid);
	}
	void Update(int now, int l, int r, int pos) {
		if (l == r) {
			Calc(now, l, r);
			return ; 
		}
		int mid = l + r >> 1;
		if (pos <= mid) Update(now << 1, l, mid, pos);
		else Update(now << 1 | 1, mid + 1, r, pos);
		pushup(now, mid);
	}
}seg;

void init(int N, int M, int h[5000][200], int v[5000][200]) {
	n = N, m = M;
	for (int i = 0; i < n; i++) for (int j = 0; j + 1 < m; j++) A[i][j] = h[i][j];
	for (int i = 0; i + 1 < n; i++) for (int j = 0; j < m; j++) B[i][j] = v[i][j];
	seg.Build(1, 0, (n - 1) / 10);
}

void changeH(int P, int Q, int W) {
	A[P][Q] = W, seg.Update(1, 0, (n - 1) / 10, P / 10);
}

void changeV(int P, int Q, int W) {
	B[P][Q] = W;
	seg.Update(1, 0, (n - 1) / 10, P / 10);
	if ((P + 1) / 10 != P / 10) seg.Update(1, 0, (n - 1) / 10, (P + 1) / 10);
}

int escape(int V1, int V2) {
	return seg.T[1][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;
      |      ^~~
wombats.cpp: In member function 'void Segment_tree::Build(int, int, int)':
wombats.cpp:51:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |   int mid = l + r >> 1;
      |             ~~^~~
wombats.cpp: In member function 'void Segment_tree::Update(int, int, int, int)':
wombats.cpp:60:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   60 |   int mid = l + r >> 1;
      |             ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12492 KB Output is correct
2 Correct 7 ms 12436 KB Output is correct
3 Correct 86 ms 14080 KB Output is correct
4 Correct 8 ms 12408 KB Output is correct
5 Correct 7 ms 12444 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 4 ms 588 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 80 ms 1584 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 3168 KB Output is correct
2 Correct 119 ms 3148 KB Output is correct
3 Correct 181 ms 3172 KB Output is correct
4 Correct 158 ms 3172 KB Output is correct
5 Correct 155 ms 3148 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 571 ms 3176 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 21032 KB Output is correct
2 Correct 19 ms 21004 KB Output is correct
3 Correct 17 ms 21068 KB Output is correct
4 Correct 57 ms 21776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 157 ms 3168 KB Output is correct
2 Correct 139 ms 3064 KB Output is correct
3 Correct 189 ms 3184 KB Output is correct
4 Correct 164 ms 3172 KB Output is correct
5 Correct 190 ms 3144 KB Output is correct
6 Correct 13 ms 21068 KB Output is correct
7 Correct 13 ms 21068 KB Output is correct
8 Correct 13 ms 21068 KB Output is correct
9 Correct 65 ms 21828 KB Output is correct
10 Correct 8 ms 12492 KB Output is correct
11 Correct 9 ms 12492 KB Output is correct
12 Correct 87 ms 14028 KB Output is correct
13 Correct 8 ms 12492 KB Output is correct
14 Correct 8 ms 12492 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
21 Correct 2 ms 580 KB Output is correct
22 Correct 2 ms 588 KB Output is correct
23 Correct 2 ms 588 KB Output is correct
24 Correct 1 ms 588 KB Output is correct
25 Correct 105 ms 1612 KB Output is correct
26 Correct 1 ms 588 KB Output is correct
27 Correct 546 ms 3168 KB Output is correct
28 Correct 1426 ms 99284 KB Output is correct
29 Correct 1558 ms 81844 KB Output is correct
30 Correct 1618 ms 81780 KB Output is correct
31 Correct 1561 ms 100296 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 157 ms 3168 KB Output is correct
2 Correct 120 ms 3072 KB Output is correct
3 Correct 167 ms 3172 KB Output is correct
4 Correct 205 ms 3112 KB Output is correct
5 Correct 188 ms 3164 KB Output is correct
6 Correct 16 ms 21044 KB Output is correct
7 Correct 12 ms 21068 KB Output is correct
8 Correct 13 ms 21080 KB Output is correct
9 Correct 55 ms 21812 KB Output is correct
10 Correct 8 ms 12400 KB Output is correct
11 Correct 9 ms 12452 KB Output is correct
12 Correct 99 ms 14052 KB Output is correct
13 Correct 8 ms 12488 KB Output is correct
14 Correct 8 ms 12492 KB Output is correct
15 Correct 2257 ms 174268 KB Output is correct
16 Correct 6573 ms 175792 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
21 Correct 1 ms 588 KB Output is correct
22 Correct 2 ms 588 KB Output is correct
23 Correct 1 ms 588 KB Output is correct
24 Correct 1 ms 588 KB Output is correct
25 Correct 1 ms 588 KB Output is correct
26 Correct 1 ms 588 KB Output is correct
27 Correct 79 ms 1616 KB Output is correct
28 Correct 1 ms 588 KB Output is correct
29 Correct 515 ms 3188 KB Output is correct
30 Correct 1432 ms 99272 KB Output is correct
31 Correct 4877 ms 174976 KB Output is correct
32 Correct 4860 ms 174988 KB Output is correct
33 Correct 1625 ms 81808 KB Output is correct
34 Correct 5679 ms 144452 KB Output is correct
35 Correct 1534 ms 81852 KB Output is correct
36 Correct 5718 ms 144476 KB Output is correct
37 Correct 1527 ms 100260 KB Output is correct
38 Correct 4987 ms 175608 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 5939 ms 144500 KB Output is correct