Submission #798503

# Submission time Handle Problem Language Result Execution time Memory
798503 2023-07-30T19:06:50 Z QwertyPi Wombats (IOI13_wombats) C++14
100 / 100
5174 ms 181740 KB
#include "wombats.h"
#include <bits/stdc++.h>

using namespace std;
const int R_MAX = 5000;
const int C_MAX = 200;
const int K = 10;
const int R_DIV_K_MUL_2 = 1024;
const int INF = 1 << 30;
int R, C, H[R_MAX][C_MAX], V[R_MAX][C_MAX];
int A[R_MAX / K][C_MAX][C_MAX];
int st[R_DIV_K_MUL_2][C_MAX][C_MAX], OPT[C_MAX][C_MAX];
bool chmin(int& x, int y){
	if(x > y){
		x = y; return true;
	}
	return false;
}


int DP[C_MAX][C_MAX];
void init(){
	for(int i = 0; i < C; i++) for(int j = 0; j < C; j++) DP[i][j] = i == j ? 0 : INF;
}

void process(int row){
	for(int i = 0; i < C; i++){
		for(int j = 0; j < C; j++){
			for(int k = j - 1; k >= 0; k--){
				if(!chmin(DP[i][k], DP[i][k + 1] + H[row][k])){
					break;
				}
			}
			for(int k = j + 1; k < C; k++){
				if(!chmin(DP[i][k], DP[i][k - 1] + H[row][k - 1])){
					break;
				}
			}
		}
	}
	for(int i = 0; i < C; i++){
		for(int j = 0; j < C; j++){
			DP[i][j] += V[row][j];
		}
	}
}

int opt(int i, int j){
	if(i < 0 || j < 0) return 0;
	if(i >= C || j >= C) return C - 1;
	return OPT[i][j];
}

void st_merge(int v, int vl, int vr){
	for(int i = 0; i < C; i++) for(int j = 0; j < C; j++) st[v][i][j] = INF;
	for(int d = -C + 1; d <= C - 1; d++){
		for(int i = 0; i < C; i++){
			int j = i - d; if(j < 0 || j >= C) continue;
			for(int k = opt(i - 1, j); k <= opt(i, j + 1); k++){
				if(st[v][i][j] > st[vl][i][k] + st[vr][k][j]) OPT[i][j] = k, st[v][i][j] = st[vl][i][k] + st[vr][k][j];
			}
		}
	}
}

void st_update(int p, int v, int l, int r){
	if(l == r){
		for(int i = 0; i < C; i++) for(int j = 0; j < C; j++) st[v][i][j] = DP[i][j];
		return;
	}
	int m = (l + r) / 2;
	if(p <= m) st_update(p, v * 2 + 1, l, m);
	else st_update(p, v * 2 + 2, m + 1, r);
	st_merge(v, v * 2 + 1, v * 2 + 2);
}

void recalc(int part = -1){
	if(part == -1){
		for(int p = 0; p < R / K; p++) recalc(p);
		return;
	}
	init();
	for(int r = part * K; r < (part + 1) * K; r++){
		process(r);
	}
	st_update(part, 0, 0, R / K - 1);
}

void init(int R, int C, int H[5000][200], int V[5000][200]) {
    ::R = (R + K - 1) / K * K, ::C = C;
    for(int i = 0; i < R; i++){
    	for(int j = 0; j < C - 1; j++){
    		::H[i][j] = H[i][j];
		}
	}
	for(int i = R; i < ::R; i++){
		for(int j = 0; j < C - 1; j++){
			::H[i][j] = INF;
		}
	}
	for(int i = 0; i < R - 1; i++){
		for(int j = 0; j < C; j++){
			::V[i][j] = V[i][j];
		}
	}
	recalc();
}

void changeH(int P, int Q, int W) {
	::H[P][Q] = W;
	recalc(P / K);
}

void changeV(int P, int Q, int W) {
	::V[P][Q] = W;
	recalc(P / K);
}

int escape(int V1, int V2) {
	return st[0][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;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 12372 KB Output is correct
2 Correct 6 ms 12480 KB Output is correct
3 Correct 59 ms 14396 KB Output is correct
4 Correct 6 ms 12500 KB Output is correct
5 Correct 6 ms 12500 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 444 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 448 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 53 ms 2004 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 2376 KB Output is correct
2 Correct 75 ms 2400 KB Output is correct
3 Correct 102 ms 2436 KB Output is correct
4 Correct 88 ms 2432 KB Output is correct
5 Correct 86 ms 2388 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 393 ms 2424 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 21036 KB Output is correct
2 Correct 9 ms 21076 KB Output is correct
3 Correct 11 ms 21108 KB Output is correct
4 Correct 38 ms 22168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 2432 KB Output is correct
2 Correct 72 ms 2396 KB Output is correct
3 Correct 86 ms 2432 KB Output is correct
4 Correct 88 ms 2432 KB Output is correct
5 Correct 85 ms 2412 KB Output is correct
6 Correct 9 ms 21056 KB Output is correct
7 Correct 9 ms 21016 KB Output is correct
8 Correct 10 ms 21076 KB Output is correct
9 Correct 37 ms 22124 KB Output is correct
10 Correct 6 ms 12372 KB Output is correct
11 Correct 8 ms 12448 KB Output is correct
12 Correct 58 ms 14408 KB Output is correct
13 Correct 6 ms 12384 KB Output is correct
14 Correct 8 ms 12492 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 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 444 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 53 ms 1672 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 375 ms 2356 KB Output is correct
28 Correct 1184 ms 98488 KB Output is correct
29 Correct 1152 ms 80912 KB Output is correct
30 Correct 1172 ms 80996 KB Output is correct
31 Correct 1235 ms 99456 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 2348 KB Output is correct
2 Correct 79 ms 2336 KB Output is correct
3 Correct 87 ms 2348 KB Output is correct
4 Correct 87 ms 2260 KB Output is correct
5 Correct 87 ms 2332 KB Output is correct
6 Correct 12 ms 21048 KB Output is correct
7 Correct 10 ms 20984 KB Output is correct
8 Correct 11 ms 21024 KB Output is correct
9 Correct 37 ms 21804 KB Output is correct
10 Correct 6 ms 12372 KB Output is correct
11 Correct 6 ms 12372 KB Output is correct
12 Correct 58 ms 13952 KB Output is correct
13 Correct 6 ms 12372 KB Output is correct
14 Correct 6 ms 12372 KB Output is correct
15 Correct 1775 ms 172660 KB Output is correct
16 Correct 5174 ms 178496 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 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 468 KB Output is correct
26 Correct 1 ms 444 KB Output is correct
27 Correct 53 ms 2824 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 372 ms 2388 KB Output is correct
30 Correct 1189 ms 102264 KB Output is correct
31 Correct 4976 ms 181068 KB Output is correct
32 Correct 4916 ms 181048 KB Output is correct
33 Correct 1160 ms 84408 KB Output is correct
34 Correct 4728 ms 149844 KB Output is correct
35 Correct 1183 ms 84456 KB Output is correct
36 Correct 4865 ms 149896 KB Output is correct
37 Correct 1254 ms 103936 KB Output is correct
38 Correct 4672 ms 181740 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 4916 ms 149976 KB Output is correct