답안 #1067824

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1067824 2024-08-21T04:02:49 Z sleepntsheep 웜뱃 (IOI13_wombats) C++17
9 / 100
564 ms 13396 KB
#include "wombats.h"
#include <cstdio>
#include <set>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

template <typename T>
using ve = vector<T>;


int r, c, at[9999], h[5000][200], v[5000][200], ph[5000][101];
int sum = 0;

int ans_5[100][100];

void calc_sub5_dp() {
	if (c == 1) return ;
	static int dp5[5000][100];


	for (int i = 0; i < r; ++i) {
		for (int j = 0; j + 1 < c; ++j) {
			ph[i][j + 1] = ph[i][j] + h[i][j];
		}
	}

	for (int ii = 0; ii < c; ++ii) {
		/* find answer for (V1, V2) where V1 = ii */
		memset(dp5, 63, sizeof dp5);
		dp5[0][ii] = 0;
		for (int i = 0; i < c; ++i)
			if (i < ii)
				dp5[0][i] = ph[0][ii] - ph[0][i];
			else if (i > ii)
				dp5[0][i] = ph[0][i] - ph[0][ii];

		for (int i = 1; i < r; ++i) {
			for (int j = 0; j < c; ++j)
				dp5[i][j] = dp5[i - 1][j] + v[i - 1][j];

			static int pre[102], suf[102]; /* annoying ahh math */ 

			pre[0] = dp5[i][0]; /* - ph[i][0] = 0; */
			for (int j = 1; j < c; ++j)
				pre[i] = min(pre[i - 1], dp5[i][j] - ph[i][j]);
			suf[c - 1] = dp5[i][c - 1] + ph[i][c - 1];
			for (int j = c - 2; j >= 0; --j)
				suf[i] = min(suf[i + 1], dp5[i][j] + ph[i][j]);

			for (int j = 1; j + 1 < c; ++j)
				dp5[i][j] = min({dp5[i][j], ph[i][j] + pre[j - 1],
							suf[j + 1] - ph[i][j]});
			dp5[i][0] = min(dp5[i][0], suf[1] - ph[i][0]);
			if (c > 1)
				dp5[i][c-1] = min(dp5[i][c-1], ph[i][c-1] + pre[c-2]);
		}
		for (int jj = 0; jj < c; ++jj) ans_5[ii][jj] = dp5[r - 1][jj];
	}
}

void changeH(int P, int Q, int W) {
	if (c <= 100) {
		h[P][Q] = W;
		calc_sub5_dp();
	}
}

void changeV(int P, int Q, int W) {
	if (c == 1) {
		sum += W - at[P];
		at[P] = W;
	} else if (c <= 100) {
		v[P][Q] = W;
		calc_sub5_dp();
	}
}


void init(int R, int C, int H[5000][200], int V[5000][200]) {
	r = R, c = C;

	if (c == 1)
		for (int i = 0; i < r; ++i) changeV(i, 0, V[i][0]);

	if (c <= 100) {
		calc_sub5_dp();
	}

}

int escape(int V1, int V2) {
	if (c == 1)
		return sum;
	else if (c <= 100) {
		return ans_5[V1][V2];
	}
	return 0;
}

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;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4188 KB Output is correct
2 Correct 3 ms 4188 KB Output is correct
3 Correct 35 ms 5860 KB Output is correct
4 Correct 2 ms 4184 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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 Incorrect 2 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 542 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 98 ms 13396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 564 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 547 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -