답안 #1067878

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1067878 2024-08-21T05:11:06 Z sleepntsheep 웜뱃 (IOI13_wombats) C++17
컴파일 오류
0 ms 0 KB
#pragma GCC optimize("O3,unroll-loops")
#include "wombats.h"
#include <cstdio>
#include <set>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cassert>
using namespace std;

#ifndef ROW
#define ROW 5000
#endif

int r, c, h[ROW][100], v[ROW][100];
int ans[100][100], ansrev[100][100], vis[100];


void calc_ii(int 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 = 0; i < r; ++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) ans[ii][jj] = dp[(r - 1) & 1][jj];
	vis[ii] = 1;
}

void calcrev_ii(int ii) {
	static int dp[2][100];
	/* find answer for (V1, V2) where V2 = ii */
	memset(dp[0], 63, sizeof dp[0]);
	dp[[0][ii] = 0;
	int I = 0;
	for (int i = r - 1; i >= 0; --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]);
		if (i)
			for (int j = 0; j < c; ++j)
				dp[!I][j] = dp[I][j] + v[i - 1][j];
	}
	for (int jj = 0; jj < c; ++jj) ansrev[ii][jj] = dp[!I][jj];
	visrev[ii] = 1;
}


void changeH(int P, int Q, int W) {
	h[P][Q] = W;
	for (int i = 0; i < 100; ++i) vis[i] = 0, visrev[i] = 0;
}

void changeV(int P, int Q, int W) {
	v[P][Q] = W;
	for (int i = 0; i < 100; ++i) vis[i] = 0, visrev[i] = 0;
}

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 < c; ++i) vis[i] = 0, visrev[i] = 0;
}

int escape(int V1, int V2) {
	if (visrev[V2]) return ansrev[V2][V1];
	if (vis[V1]) return ans[V1][V2];
	calc_ii(V1); calcrev_ii(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 calcrev_ii(int)':
wombats.cpp:49:4: error: two consecutive '[' shall only introduce an attribute before '[' token
   49 |  dp[[0][ii] = 0;
      |    ^
wombats.cpp:69:2: error: 'visrev' was not declared in this scope; did you mean 'ansrev'?
   69 |  visrev[ii] = 1;
      |  ^~~~~~
      |  ansrev
wombats.cpp: In function 'void changeH(int, int, int)':
wombats.cpp:75:44: error: 'visrev' was not declared in this scope; did you mean 'ansrev'?
   75 |  for (int i = 0; i < 100; ++i) vis[i] = 0, visrev[i] = 0;
      |                                            ^~~~~~
      |                                            ansrev
wombats.cpp: In function 'void changeV(int, int, int)':
wombats.cpp:80:44: error: 'visrev' was not declared in this scope; did you mean 'ansrev'?
   80 |  for (int i = 0; i < 100; ++i) vis[i] = 0, visrev[i] = 0;
      |                                            ^~~~~~
      |                                            ansrev
wombats.cpp: In function 'void init(int, int, int (*)[200], int (*)[200])':
wombats.cpp:89:42: error: 'visrev' was not declared in this scope; did you mean 'ansrev'?
   89 |  for (int i = 0; i < c; ++i) vis[i] = 0, visrev[i] = 0;
      |                                          ^~~~~~
      |                                          ansrev
wombats.cpp: In function 'int escape(int, int)':
wombats.cpp:93:6: error: 'visrev' was not declared in this scope; did you mean 'ansrev'?
   93 |  if (visrev[V2]) return ansrev[V2][V1];
      |      ^~~~~~
      |      ansrev