Submission #1068041

# Submission time Handle Problem Language Result Execution time Memory
1068041 2024-08-21T06:52:40 Z sleepntsheep Wombats (IOI13_wombats) C++17
55 / 100
20000 ms 30588 KB
#pragma GCC optimize("O3,unroll-loops")
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
using namespace std;

#include "wombats.h"

#ifndef ROW
#define ROW 5000
#endif

#define COL 100
constexpr int B = 1300;
constexpr int ROW_BY_B = (ROW / B) + 10;

int r, c, h[ROW][COL], v[ROW + 1][COL];

int L[9999], R[9999], By[9999], a[ROW_BY_B][COL][COL], ans[COL][COL];

void calc(int blk) {
	for (int ii = 0; ii < c; ++ii) {
		static int dp[2][COL];
		/* find answer for (V1, V2) where V1 = ii */
		memset(dp[0], 63, sizeof dp[0]);
		dp[0][ii] = 0;
		int I = 0;

		for (int i = L[blk]; i <= R[blk]; ++i, I ^= 1) {
			static int pre[COL], suf[COL], ph[COL]; /* annoying ahh math */ 
			ph[0] = 0;
			for (int j = 0; j + 1 < c; ++j)
				ph[j + 1] = ph[j] + h[i][j];

			pre[0] = dp[I][0];
			for (int j = 1; j < c; ++j) pre[j] = min(pre[j - 1], dp[I][j] - ph[j]);
			suf[c - 1] = dp[I][c - 1] + ph[c - 1];
			for (int j = c - 2; j >= 0; --j) suf[j] = min(suf[j + 1], dp[I][j] + ph[j]);

			for (int j = 0; j < c; ++j) dp[I][j] = min(ph[j] + pre[j], suf[j] - ph[j]);
			for (int j = 0; j < c; ++j) dp[!I][j] = dp[I][j] + v[i][j];
		}
		memcpy(a[blk][ii], dp[I], sizeof *dp);
	}
}

void merg(int up[COL][COL], int down[COL][COL], int out[COL][COL]) {
	static int buf[COL][COL];
	for (int i = 0; i < c; ++i) for (int j = 0; j < c; ++j) {
		buf[i][j] = 1e9;
		for (int k = 0; k < c; ++k)
			buf[i][j] = min({buf[i][j], up[i][k]+ down[k][j]});
	}
	for (int i = 0; i < c; ++i) for (int j = 0; j < c; ++j) out[i][j] = buf[i][j];

return;
	for (int i = 0; i < c; ++i) for (int j = 0; j < c; ++j) {
		buf[i][j] = 1e9;
		for (int k = 0; k < c; ++k)
			buf[i][k] = min(buf[i][k], up[i][j] + down[j][k]);
	}
	for (int i = 0; i < c; ++i) for (int j = 0; j < c; ++j) out[i][j] = buf[i][j];
}

void CalcAns() {
	for (int i = 0; i < c; ++i) for (int j = 0; j < c; ++j) ans[i][j] = a[0][i][j];
	for (int i = 1; i * B < r; ++i)
		merg(ans, a[i], ans);
}

int outdated = 0;

void changeH(int P, int Q, int W) {
	h[P][Q] = W;
	calc(By[P]);
	outdated = 1;
}

void changeV(int P, int Q, int W) {
	v[P][Q] = W;
	calc(By[P]);
	outdated = 1;
}

void init(int R, int C, int H[ROW][200], int V[ROW][200]) {
	r = R, c = C;
	for (int i = 0; i + 1 < r; ++i) for (int j = 0; j < c; ++j) v[i][j] = V[i][j];
	for (int i = 0 ; i < r; ++i) for (int j = 0; j + 1 < c; ++j) h[i][j] = H[i][j];

	for (int i = 0; i * B < r; ++i) {
		L[i] = i * B;
		::R[i] = min(r - 1, i * B + B - 1);
		calc(i);
		for (int j = L[i]; j <= ::R[i]; ++j) By[j] = i;
	}

	outdated = 1;
}

int escape(int V1, int V2) { if (outdated) --outdated, CalcAns(); return ans[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 6 ms 6232 KB Output is correct
2 Correct 6 ms 6236 KB Output is correct
3 Correct 41 ms 7888 KB Output is correct
4 Correct 6 ms 6236 KB Output is correct
5 Correct 6 ms 6368 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 36 ms 1464 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 774 ms 732 KB Output is correct
2 Correct 712 ms 600 KB Output is correct
3 Correct 767 ms 604 KB Output is correct
4 Correct 773 ms 760 KB Output is correct
5 Correct 772 ms 852 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 4284 ms 764 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 12124 KB Output is correct
2 Correct 28 ms 12120 KB Output is correct
3 Correct 26 ms 12120 KB Output is correct
4 Correct 49 ms 12884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 769 ms 716 KB Output is correct
2 Correct 710 ms 756 KB Output is correct
3 Correct 774 ms 760 KB Output is correct
4 Correct 798 ms 600 KB Output is correct
5 Correct 774 ms 604 KB Output is correct
6 Correct 37 ms 12216 KB Output is correct
7 Correct 29 ms 12128 KB Output is correct
8 Correct 30 ms 12124 KB Output is correct
9 Correct 46 ms 12812 KB Output is correct
10 Correct 6 ms 6236 KB Output is correct
11 Correct 6 ms 6236 KB Output is correct
12 Correct 42 ms 7888 KB Output is correct
13 Correct 6 ms 6488 KB Output is correct
14 Correct 7 ms 6360 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 38 ms 1368 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 3967 ms 760 KB Output is correct
28 Execution timed out 20048 ms 12624 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 787 ms 604 KB Output is correct
2 Correct 687 ms 824 KB Output is correct
3 Correct 771 ms 856 KB Output is correct
4 Correct 786 ms 824 KB Output is correct
5 Correct 765 ms 604 KB Output is correct
6 Correct 25 ms 12220 KB Output is correct
7 Correct 27 ms 12124 KB Output is correct
8 Correct 29 ms 12292 KB Output is correct
9 Correct 68 ms 13392 KB Output is correct
10 Correct 7 ms 6232 KB Output is correct
11 Correct 6 ms 6236 KB Output is correct
12 Correct 42 ms 8496 KB Output is correct
13 Correct 7 ms 6232 KB Output is correct
14 Correct 6 ms 6388 KB Output is correct
15 Runtime error 9224 ms 30588 KB Execution killed with signal 11
16 Halted 0 ms 0 KB -