Submission #1068006

# Submission time Handle Problem Language Result Execution time Memory
1068006 2024-08-21T06:37:50 Z sleepntsheep Wombats (IOI13_wombats) C++17
Compilation error
0 ms 0 KB
#pragma GCC optimize("O3,unroll-loops")
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cassert>
using namespace std;

#include "wombats.h"

#ifndef ROW
#define ROW 5000
#endif

#define COL 200
constexpr int B = 400;
constexpr int ROW_BY_B = 15;

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];
		}
		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];
}

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][COL], int V[ROW][COL]) {
	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 = 1) --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;
      |      ^~~
wombats.cpp:22:35: error: 'ROW_by_B' was not declared in this scope; did you mean 'ROW_BY_B'?
   22 | int L[9999], R[9999], By[9999], a[ROW_by_B][COL][COL], ans[COL][COL];
      |                                   ^~~~~~~~
      |                                   ROW_BY_B
wombats.cpp: In function 'void calc(int)':
wombats.cpp:47:4: error: 'a' was not declared in this scope
   47 |    a[blk][ii][jj] = dp[I][jj];
      |    ^
wombats.cpp: In function 'void CalcAns()':
wombats.cpp:62:70: error: 'a' was not declared in this scope
   62 |  for (int i = 0; i < c; ++i) for (int j = 0; j < c; ++j) ans[i][j] = a[0][i][j];
      |                                                                      ^
wombats.cpp:64:13: error: 'a' was not declared in this scope
   64 |   merg(ans, a[i], ans);
      |             ^
wombats.cpp: In function 'int escape(int, int)':
wombats.cpp:96:43: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   96 | int escape(int V1, int V2) { if (outdated = 1) --outdated, CalcAns(); return ans[V1][V2]; }
      |                                  ~~~~~~~~~^~~