답안 #878843

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878843 2023-11-25T10:32:22 Z SanguineChameleon 축구 경기장 (IOI23_soccer) C++17
8 / 100
4500 ms 4544 KB
#include "soccer.h"
#include <bits/stdc++.h>
using namespace std;

const int maxN = 2e3 + 20;
int A[maxN][maxN];
int prv[maxN][maxN][2];
int top[maxN][maxN];
int bottom[maxN][maxN];
vector<pair<int, int>> group[maxN];
int dp[maxN][maxN];

int biggest_stadium(int N, vector<vector<int>> _A) {
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			A[i][j] = _A[i - 1][j - 1];
		}
	}
	vector<pair<int, int>> cells;
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			if (A[i][j] == 0) {
				cells.emplace_back(i, j);
			}
		}
	}
	int real_res = 0;
	for (int mask = 0; mask < (1 << (int)cells.size()); mask++) {
		vector<pair<int, int>> choice;
		for (int i = 0; i < (int)cells.size(); i++) {
			if ((mask >> i) & 1) {
				choice.push_back(cells[i]);
			}
		}
		bool ok = true;
		for (auto [i1, j1]: choice) {
			for (auto [i2, j2]: choice) {
				bool check1 = true;
				bool check2 = true;
				for (int k = min(j1, j2); k <= max(j1, j2); k++) {
					check1 &= (A[i1][k] == 0);
					check2 &= (A[i2][k] == 0);
				}
				for (int k = min(i1, i2); k <= max(i1, i2); k++) {
					check1 &= (A[k][j2] == 0);
					check2 &= (A[k][j1] == 0);
				}
				ok &= (check1 || check2);
			}
		}
		if (ok) {
			real_res = max(real_res, (int)choice.size());
		}
	}
	return real_res;
	for (int i = 0; i <= N + 1; i++) {
		A[0][i] = 1;
		A[N + 1][i] = 1;
		A[i][0] = 1;
		A[i][N + 1] = 1;
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			for (int k = 0; k < 2; k++) {
				if (A[i][j] == k) {
					prv[i][j][k] = j;
				}
				else {
					prv[i][j][k] = prv[i][j - 1][k];
				}
			}
		}
	}
	for (int j = 0; j <= N; j++) {
		top[0][j] = 0;
		bottom[N + 1][j] = N + 1;
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= N; j++) {
			if (A[i - 1][j] == 1) {
				top[i][j] = i - 1;
			}
			else {
				top[i][j] = top[i - 1][j];
			}
		}
	}
	for (int i = N; i >= 1; i--) {
		for (int j = 0; j <= N; j++) {
			if (A[i + 1][j] == 1) {
				bottom[i][j] = i + 1;
			}
			else {
				bottom[i][j] = bottom[i + 1][j];
			}
		}
	}
	for (int i = N; i >= 1; i--) {
		for (int j = 1; j <= N; j++) {
			if (A[i][j] == 0) {
				if (A[i][j - 1] == 0) {
					top[i][j] = max(top[i][j], top[i][j - 1]);
					bottom[i][j] = min(bottom[i][j], bottom[i][j - 1]);
				}
				group[j - prv[i][j][1]].emplace_back(i, j);
			}
		}
	}
	int res = 0;
	for (int W = N; W >= 1; W--) {
		for (auto [i, j]: group[W]) {
			if (top[i][j] + 1 <= top[i][prv[i][j][1]]) {
				dp[prv[i][j][1]][j] = max(dp[prv[i][j][1]][j], dp[i][j]);
				continue;
			}
			int L = prv[i][j][1] + 1;
			int R = j;
			int T = top[i][j] + 1;
			int B = bottom[i][j] - 1;
			//cout << i << " " << j << " " << L << " " << R << " " << T << " " << B << " " << dp[i][j] << " " << dp[i][j] + (R - L + 1) * (B - T + 1) << '\n';
			res = max(res, dp[i][j] + (R - L + 1) * (B - T + 1));
			for (int iter = 0; iter < 2; iter++) {
				int row = (iter ? B + 1 : T - 1);
				if (row < 1 || row > N) {
					continue;
				}
				int nxtR = prv[row][R][0];
				while (nxtR >= L) {
					int nxtL = max(L, prv[row][nxtR][1] + 1);
					int nxt_row = (nxtL == L ? i : row); 
					//cout << nxt_row << " " << nxtR << " " << "real?" << '\n';
					dp[nxt_row][nxtR] = max(dp[nxt_row][nxtR], dp[i][j] + ((R - L + 1) - (nxtR - nxtL + 1)) * (B - T + 1));
					nxtR = prv[row][nxtL - 1][0];
				}
			}
		}
	}
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4559 ms 4444 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB ok
2 Correct 1 ms 4444 KB ok
3 Incorrect 725 ms 4524 KB wrong
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB ok
2 Correct 1 ms 4444 KB ok
3 Correct 1 ms 4444 KB ok
4 Correct 1 ms 4444 KB ok
5 Correct 1 ms 4444 KB ok
6 Correct 1 ms 4444 KB ok
7 Correct 1 ms 4444 KB ok
8 Correct 1 ms 4444 KB ok
9 Correct 1 ms 4544 KB ok
10 Correct 1 ms 4440 KB ok
11 Correct 1 ms 4444 KB ok
12 Correct 1 ms 4444 KB ok
13 Correct 1 ms 4444 KB ok
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4559 ms 4444 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4559 ms 4444 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4559 ms 4444 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4559 ms 4444 KB Time limit exceeded
2 Halted 0 ms 0 KB -