Submission #1067972

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

#ifndef ROW
#define ROW 5000
#endif

constexpr int B = 1000;

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

int L[9999], R[9999], By[9999];

int a[100][100][100];

int ans[100][100];

void calc(int blk) {
	for (int ii = 0; ii < c; ++ii) {
		static int dp[2][100];
		/* 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[100], suf[100], ph[100]; /* 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[100][100], int down[100][100], int out[100][100]) {
	static int buf[100][100];
	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 changeH(int P, int Q, int W) {
	h[P][Q] = W;
	calc(By[P]);
	for (int i = 0; i * B < r; ++i)
		ans(out, a[i], out);
}

void changeV(int P, int Q, int W) {
	v[P][Q] = W;
	calc(By[P]);
	for (int i = 0; i * B < r; ++i)
		ans(out, a[i], out);
}

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

}

int escape(int V1, int V2) {
	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: In function 'void changeH(int, int, int)':
wombats.cpp:69:7: error: 'out' was not declared in this scope
   69 |   ans(out, a[i], out);
      |       ^~~
wombats.cpp:69:21: error: 'ans' cannot be used as a function
   69 |   ans(out, a[i], out);
      |                     ^
wombats.cpp: In function 'void changeV(int, int, int)':
wombats.cpp:76:7: error: 'out' was not declared in this scope
   76 |   ans(out, a[i], out);
      |       ^~~
wombats.cpp:76:21: error: 'ans' cannot be used as a function
   76 |   ans(out, a[i], out);
      |                     ^
wombats.cpp: In function 'void init(int, int, int (*)[200], int (*)[200])':
wombats.cpp:91:28: error: invalid types 'int[int]' for array subscript
   91 |   for (int j = L[i]; j <= R[i]; ++j) By[j] = i;
      |                            ^
In file included from /usr/include/c++/10/bits/stl_tree.h:63,
                 from /usr/include/c++/10/set:60,
                 from wombats.cpp:5:
/usr/include/c++/10/bits/stl_algobase.h: In instantiation of 'constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare) [with _Tp = int; _Compare = int]':
wombats.cpp:60:51:   required from here
/usr/include/c++/10/bits/stl_algobase.h:281:17: error: '__comp' cannot be used as a function
  281 |       if (__comp(__b, __a))
      |           ~~~~~~^~~~~~~~~~