Submission #98092

# Submission time Handle Problem Language Result Execution time Memory
98092 2019-02-20T16:03:53 Z tincamatei Wombats (IOI13_wombats) C++14
76 / 100
20000 ms 32752 KB
#include "wombats.h"
#include <bits/stdc++.h>
 
using namespace std;
 
const int MAX_C = 200;
const int MAX_R = 5000;
const int INF = 1000000000;
const int BUCK = 70;

int R, C;
int H[MAX_R][MAX_C], V[MAX_R][MAX_C];
int sp[MAX_R][MAX_C];
int a[MAX_C][MAX_C];
int aux[MAX_C][MAX_C];

struct Matrix {
	int dp[MAX_C][MAX_C];
	Matrix() {
		for(int i = 0; i < C; ++i)
			for(int j = 0; j < C; ++j)
				dp[i][j] = INF;
	}
 
	void operator* (const Matrix &x) {
		for(int i = 0; i < C; ++i)
			for(int j = 0; j < C; ++j)
				aux[i][j] = INF;
		
		for(int i = 0; i < C; ++i) {
			for(int j = 0; j < C; ++j) {
				int dist = dp[i][j] + x.dp[j][i];
				if(dist < aux[i][i]) {
					aux[i][i] = dist;
					a[i][i] = j;
				}
			}
		}
 
		for(int d = 1; d < C; ++d) {
			for(int i = 0; i < C - d; ++i) {
				int j = i + d;
				int st, dr;
				st = a[i][j - 1];
				dr = a[i + 1][j];
				for(int k = st; k <= dr; ++k) {
					int dist = dp[i][k] + x.dp[k][j];
					if(dist < aux[i][j]) {
						aux[i][j] = dist;
						a[i][j] = k;
					}
				}
			}
 
			for(int i = d; i < C; ++i) {
				int j = i - d;
				int st, dr;
				st = a[i - 1][j];
				dr = a[i][j + 1];
				for(int k = st; k <= dr; ++k) {
					int dist = dp[i][k] + x.dp[k][j];
					if(dist < aux[i][j]) {
						aux[i][j] = dist;
						a[i][j] = k;
					}
				}
			}
		}

		for(int i = 0; i < C; ++i)
			for(int j = 0; j < C; ++j)
				dp[i][j] = aux[i][j];
	}
} dp[MAX_R / BUCK + 1];
 
Matrix rez, row;
 
void initzero(Matrix &x) {
	for(int i = 0; i < C; ++i)
		for(int j = 0; j < C; ++j)
			if(i == j)
				x.dp[i][j] = 0;
			else
				x.dp[i][j] = INF;
}
 
void initrow(Matrix &x, int r) {
	for(int i = 0; i < C; ++i)
		for(int j = 0; j < C; ++j)
			x.dp[i][j] = abs(sp[r][i] - sp[r][j]) + V[r][j];
}

void updBuck(Matrix &x, int b) {
	initzero(x);
	for(int i = b * BUCK; i < (b + 1) * BUCK && i < R; ++i) {
		initrow(row, i);
		x * row; // Not gonna lie, this is really disgusting
	}
}
 
void calcrez() {
	initzero(rez);
	for(int i = 0; i < (R + BUCK - 1) / BUCK; ++i)
		rez * dp[i];
}
 
void init(int _R, int _C, int _H[5000][200], int _V[5000][200]) {
	R = _R;
	C = _C;
	for(int i = 0; i < R; ++i)
		for(int j = 0; j < C; ++j) {
			H[i][j] = _H[i][j];
			V[i][j] = _V[i][j];
		}
 
	for(int i = 0; i < R; ++i) {
		sp[i][0] = 0;
		for(int j = 1; j < C; ++j)
			sp[i][j] = sp[i][j - 1] + H[i][j - 1];
	}
 
	for(int i = 0; i < (R + BUCK - 1) / BUCK; ++i)
		updBuck(dp[i], i);
 
	calcrez();
}
 
void changeH(int P, int Q, int W) {
	H[P][Q] = W;
	for(int i = 1; i < C; ++i)
		sp[P][i] = sp[P][i - 1] + H[P][i - 1];
	int b = P / BUCK;
	updBuck(dp[b], b);
	calcrez();
}
 
void changeV(int P, int Q, int W) {
	V[P][Q] = W;
	int b = P / BUCK;
	updBuck(dp[b], b);
	calcrez();
}
 
int escape(int V1, int V2) {
	return rez.dp[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]
  int res;
      ^~~
# Verdict Execution time Memory Grader output
1 Correct 20 ms 16256 KB Output is correct
2 Correct 16 ms 16256 KB Output is correct
3 Correct 91 ms 17924 KB Output is correct
4 Correct 18 ms 16252 KB Output is correct
5 Correct 17 ms 16248 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 356 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 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 96 ms 1668 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 404 ms 1280 KB Output is correct
2 Correct 579 ms 1272 KB Output is correct
3 Correct 773 ms 1284 KB Output is correct
4 Correct 826 ms 1272 KB Output is correct
5 Correct 1079 ms 1272 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3291 ms 1316 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 20352 KB Output is correct
2 Correct 25 ms 20224 KB Output is correct
3 Correct 29 ms 20316 KB Output is correct
4 Correct 61 ms 21140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 438 ms 1272 KB Output is correct
2 Correct 487 ms 1280 KB Output is correct
3 Correct 819 ms 1400 KB Output is correct
4 Correct 744 ms 1284 KB Output is correct
5 Correct 916 ms 1280 KB Output is correct
6 Correct 24 ms 20224 KB Output is correct
7 Correct 25 ms 20352 KB Output is correct
8 Correct 27 ms 20224 KB Output is correct
9 Correct 71 ms 21112 KB Output is correct
10 Correct 17 ms 16256 KB Output is correct
11 Correct 17 ms 16256 KB Output is correct
12 Correct 87 ms 17912 KB Output is correct
13 Correct 17 ms 16384 KB Output is correct
14 Correct 20 ms 16356 KB Output is correct
15 Correct 3 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 512 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 3 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 100 ms 1560 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3082 ms 1276 KB Output is correct
28 Correct 6737 ms 26740 KB Output is correct
29 Correct 8556 ms 22128 KB Output is correct
30 Correct 8571 ms 22144 KB Output is correct
31 Correct 6771 ms 27756 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 449 ms 1376 KB Output is correct
2 Correct 627 ms 1272 KB Output is correct
3 Correct 865 ms 1408 KB Output is correct
4 Correct 734 ms 1280 KB Output is correct
5 Correct 958 ms 1400 KB Output is correct
6 Correct 26 ms 20344 KB Output is correct
7 Correct 22 ms 20352 KB Output is correct
8 Correct 24 ms 20224 KB Output is correct
9 Correct 66 ms 20984 KB Output is correct
10 Correct 17 ms 16376 KB Output is correct
11 Correct 17 ms 16256 KB Output is correct
12 Correct 103 ms 18044 KB Output is correct
13 Correct 19 ms 16384 KB Output is correct
14 Correct 18 ms 16384 KB Output is correct
15 Correct 3043 ms 31936 KB Output is correct
16 Execution timed out 20038 ms 32752 KB Time limit exceeded
17 Halted 0 ms 0 KB -