Submission #1068065

# Submission time Handle Problem Language Result Execution time Memory
1068065 2024-08-21T07:04:02 Z sleepntsheep Wombats (IOI13_wombats) C++17
55 / 100
20000 ms 27464 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 200
constexpr int B = 300;
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) {
			int pre = 1e9, suf = 1e9;
			for (int j = 0; j < c; ++j) {
				pre = min(pre, dp[I][j] - h[i][j]);
				dp[I][j] = min(dp[I][j], h[i][j] + pre);
			}
			for (int j = c - 1; j >= 0; --j) {
				suf = min(suf, dp[I][j] + h[i][j]);
				dp[I][j] = min(dp[I][j], suf - h[i][j]);
			}

			for (int j = 0; j < c; ++j) dp[!I][j] = dp[I][j] + v[i][j];
		}
		for (int jj = 0; jj < c; ++jj)
			a[blk][ii][jj] = dp[I][jj];
	}
}

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) {
	int dl = W - h[P][Q + 1] + h[P][Q];
	for (int j = Q + 1; j < c; ++j) h[P][j] += dl;
	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 + 1] = H[i][j];
		for (int j = 0; j + 1 < c; ++j) h[i][j + 1] += 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 5 ms 8284 KB Output is correct
2 Correct 6 ms 8256 KB Output is correct
3 Correct 41 ms 9920 KB Output is correct
4 Correct 5 ms 8280 KB Output is correct
5 Correct 5 ms 8384 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 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 36 ms 1488 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 911 ms 860 KB Output is correct
2 Correct 816 ms 924 KB Output is correct
3 Correct 919 ms 924 KB Output is correct
4 Correct 930 ms 924 KB Output is correct
5 Correct 901 ms 860 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 4411 ms 856 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 15964 KB Output is correct
2 Correct 16 ms 15964 KB Output is correct
3 Correct 21 ms 15964 KB Output is correct
4 Correct 37 ms 16984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 920 ms 916 KB Output is correct
2 Correct 824 ms 856 KB Output is correct
3 Correct 927 ms 924 KB Output is correct
4 Correct 925 ms 840 KB Output is correct
5 Correct 904 ms 924 KB Output is correct
6 Correct 15 ms 15964 KB Output is correct
7 Correct 17 ms 15964 KB Output is correct
8 Correct 16 ms 16068 KB Output is correct
9 Correct 45 ms 16936 KB Output is correct
10 Correct 7 ms 8280 KB Output is correct
11 Correct 5 ms 8388 KB Output is correct
12 Correct 77 ms 9872 KB Output is correct
13 Correct 5 ms 8284 KB Output is correct
14 Correct 5 ms 8280 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 74 ms 1396 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 4534 ms 920 KB Output is correct
28 Execution timed out 20040 ms 21672 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 944 ms 1104 KB Output is correct
2 Correct 819 ms 856 KB Output is correct
3 Correct 949 ms 1016 KB Output is correct
4 Correct 935 ms 1104 KB Output is correct
5 Correct 905 ms 860 KB Output is correct
6 Correct 16 ms 15960 KB Output is correct
7 Correct 17 ms 16212 KB Output is correct
8 Correct 15 ms 15960 KB Output is correct
9 Correct 34 ms 16824 KB Output is correct
10 Correct 5 ms 8284 KB Output is correct
11 Correct 5 ms 8380 KB Output is correct
12 Correct 79 ms 9808 KB Output is correct
13 Correct 5 ms 8284 KB Output is correct
14 Correct 5 ms 8284 KB Output is correct
15 Correct 2851 ms 27464 KB Output is correct
16 Execution timed out 20101 ms 25672 KB Time limit exceeded
17 Halted 0 ms 0 KB -