답안 #1067880

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1067880 2024-08-21T05:12:06 Z sleepntsheep 웜뱃 (IOI13_wombats) C++17
55 / 100
20000 ms 24264 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], visrev[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;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 6232 KB Output is correct
2 Correct 24 ms 6232 KB Output is correct
3 Correct 64 ms 7808 KB Output is correct
4 Correct 25 ms 6236 KB Output is correct
5 Correct 24 ms 6236 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 50 ms 1408 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 604 KB Output is correct
2 Correct 8 ms 604 KB Output is correct
3 Correct 8 ms 604 KB Output is correct
4 Correct 8 ms 604 KB Output is correct
5 Correct 8 ms 604 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 344 KB Output is correct
9 Correct 5 ms 700 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 12120 KB Output is correct
2 Correct 133 ms 12148 KB Output is correct
3 Correct 121 ms 12120 KB Output is correct
4 Correct 148 ms 12884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 604 KB Output is correct
2 Correct 8 ms 604 KB Output is correct
3 Correct 10 ms 752 KB Output is correct
4 Correct 10 ms 768 KB Output is correct
5 Correct 8 ms 764 KB Output is correct
6 Correct 120 ms 12124 KB Output is correct
7 Correct 121 ms 12144 KB Output is correct
8 Correct 125 ms 12120 KB Output is correct
9 Correct 142 ms 12880 KB Output is correct
10 Correct 24 ms 6236 KB Output is correct
11 Correct 24 ms 6284 KB Output is correct
12 Correct 83 ms 7840 KB Output is correct
13 Correct 27 ms 6232 KB Output is correct
14 Correct 24 ms 6236 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 600 KB Output is correct
25 Correct 40 ms 1264 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 6 ms 604 KB Output is correct
28 Execution timed out 20075 ms 12228 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 600 KB Output is correct
2 Correct 8 ms 604 KB Output is correct
3 Correct 8 ms 748 KB Output is correct
4 Correct 9 ms 772 KB Output is correct
5 Correct 7 ms 604 KB Output is correct
6 Correct 119 ms 12148 KB Output is correct
7 Correct 126 ms 12148 KB Output is correct
8 Correct 134 ms 12124 KB Output is correct
9 Correct 139 ms 12868 KB Output is correct
10 Correct 25 ms 6312 KB Output is correct
11 Correct 24 ms 6236 KB Output is correct
12 Correct 70 ms 7848 KB Output is correct
13 Correct 24 ms 6236 KB Output is correct
14 Correct 24 ms 6236 KB Output is correct
15 Runtime error 137 ms 24264 KB Execution killed with signal 11
16 Halted 0 ms 0 KB -