답안 #878864

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878864 2023-11-25T11:08:20 Z SanguineChameleon 축구 경기장 (IOI23_soccer) C++17
100 / 100
519 ms 168744 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];
		}
	}
	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 + 1; i++) {
		for (int j = 0; j <= N + 1; 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[top[i][prv[i][j][1]]][j] = max(dp[top[i][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;
			if (top[B + 1][R + 1] + 1 <= T) {
				continue;
			}
			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); 
					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 Correct 1 ms 8536 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB ok
2 Correct 1 ms 8540 KB ok
3 Correct 1 ms 6588 KB ok
4 Correct 1 ms 8540 KB ok
5 Correct 1 ms 8540 KB ok
6 Correct 1 ms 8540 KB ok
7 Correct 3 ms 15196 KB ok
8 Correct 24 ms 35188 KB ok
9 Correct 347 ms 152664 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB ok
2 Correct 1 ms 8540 KB ok
3 Correct 1 ms 8540 KB ok
4 Correct 1 ms 8540 KB ok
5 Correct 1 ms 8540 KB ok
6 Correct 1 ms 6492 KB ok
7 Correct 1 ms 8536 KB ok
8 Correct 1 ms 8540 KB ok
9 Correct 1 ms 8540 KB ok
10 Correct 1 ms 8540 KB ok
11 Correct 1 ms 8540 KB ok
12 Correct 1 ms 8536 KB ok
13 Correct 1 ms 6492 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB ok
2 Correct 1 ms 8536 KB ok
3 Correct 1 ms 8540 KB ok
4 Correct 1 ms 8540 KB ok
5 Correct 1 ms 8540 KB ok
6 Correct 1 ms 8540 KB ok
7 Correct 1 ms 6492 KB ok
8 Correct 1 ms 8536 KB ok
9 Correct 1 ms 8540 KB ok
10 Correct 1 ms 8540 KB ok
11 Correct 1 ms 8540 KB ok
12 Correct 1 ms 8540 KB ok
13 Correct 1 ms 8536 KB ok
14 Correct 1 ms 6492 KB ok
15 Correct 1 ms 8540 KB ok
16 Correct 1 ms 8540 KB ok
17 Correct 1 ms 8540 KB ok
18 Correct 1 ms 8540 KB ok
19 Correct 1 ms 8792 KB ok
20 Correct 1 ms 6492 KB ok
21 Correct 1 ms 6492 KB ok
22 Correct 1 ms 6492 KB ok
23 Correct 1 ms 6492 KB ok
24 Correct 1 ms 6492 KB ok
25 Correct 1 ms 6492 KB ok
26 Correct 2 ms 8540 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB ok
2 Correct 1 ms 8536 KB ok
3 Correct 1 ms 8540 KB ok
4 Correct 1 ms 6588 KB ok
5 Correct 1 ms 8540 KB ok
6 Correct 1 ms 8540 KB ok
7 Correct 1 ms 8540 KB ok
8 Correct 1 ms 8540 KB ok
9 Correct 1 ms 6492 KB ok
10 Correct 1 ms 8536 KB ok
11 Correct 1 ms 8540 KB ok
12 Correct 1 ms 8540 KB ok
13 Correct 1 ms 8540 KB ok
14 Correct 1 ms 8540 KB ok
15 Correct 1 ms 8536 KB ok
16 Correct 1 ms 6492 KB ok
17 Correct 1 ms 8540 KB ok
18 Correct 1 ms 8540 KB ok
19 Correct 1 ms 8540 KB ok
20 Correct 1 ms 8540 KB ok
21 Correct 1 ms 8792 KB ok
22 Correct 1 ms 6492 KB ok
23 Correct 1 ms 6492 KB ok
24 Correct 1 ms 6492 KB ok
25 Correct 1 ms 6492 KB ok
26 Correct 1 ms 6492 KB ok
27 Correct 1 ms 6492 KB ok
28 Correct 2 ms 8540 KB ok
29 Correct 1 ms 6492 KB ok
30 Correct 1 ms 8796 KB ok
31 Correct 1 ms 8796 KB ok
32 Correct 1 ms 8792 KB ok
33 Correct 1 ms 6748 KB ok
34 Correct 1 ms 6748 KB ok
35 Correct 1 ms 6748 KB ok
36 Correct 1 ms 6748 KB ok
37 Correct 1 ms 6748 KB ok
38 Correct 1 ms 6748 KB ok
39 Correct 1 ms 6748 KB ok
40 Correct 2 ms 8540 KB ok
41 Correct 2 ms 8792 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB ok
2 Correct 1 ms 8536 KB ok
3 Correct 1 ms 8540 KB ok
4 Correct 1 ms 6588 KB ok
5 Correct 1 ms 8540 KB ok
6 Correct 1 ms 8540 KB ok
7 Correct 1 ms 8540 KB ok
8 Correct 1 ms 8540 KB ok
9 Correct 1 ms 6492 KB ok
10 Correct 1 ms 8536 KB ok
11 Correct 1 ms 8540 KB ok
12 Correct 1 ms 8540 KB ok
13 Correct 1 ms 8540 KB ok
14 Correct 1 ms 8540 KB ok
15 Correct 1 ms 8536 KB ok
16 Correct 1 ms 6492 KB ok
17 Correct 1 ms 8540 KB ok
18 Correct 1 ms 8540 KB ok
19 Correct 1 ms 8540 KB ok
20 Correct 1 ms 8540 KB ok
21 Correct 1 ms 8792 KB ok
22 Correct 1 ms 6492 KB ok
23 Correct 1 ms 6492 KB ok
24 Correct 1 ms 6492 KB ok
25 Correct 1 ms 6492 KB ok
26 Correct 1 ms 6492 KB ok
27 Correct 1 ms 6492 KB ok
28 Correct 2 ms 8540 KB ok
29 Correct 1 ms 6492 KB ok
30 Correct 1 ms 8796 KB ok
31 Correct 1 ms 8796 KB ok
32 Correct 1 ms 8792 KB ok
33 Correct 1 ms 6748 KB ok
34 Correct 1 ms 6748 KB ok
35 Correct 1 ms 6748 KB ok
36 Correct 1 ms 6748 KB ok
37 Correct 1 ms 6748 KB ok
38 Correct 1 ms 6748 KB ok
39 Correct 1 ms 6748 KB ok
40 Correct 2 ms 8540 KB ok
41 Correct 2 ms 8792 KB ok
42 Correct 30 ms 36228 KB ok
43 Correct 28 ms 35984 KB ok
44 Correct 26 ms 36700 KB ok
45 Correct 26 ms 36688 KB ok
46 Correct 27 ms 36404 KB ok
47 Correct 24 ms 35664 KB ok
48 Correct 24 ms 28500 KB ok
49 Correct 24 ms 28504 KB ok
50 Correct 23 ms 30676 KB ok
51 Correct 26 ms 31192 KB ok
52 Correct 22 ms 27228 KB ok
53 Correct 21 ms 26460 KB ok
54 Correct 21 ms 28252 KB ok
55 Correct 21 ms 27740 KB ok
56 Correct 21 ms 30300 KB ok
57 Correct 28 ms 36432 KB ok
58 Correct 26 ms 36472 KB ok
59 Correct 26 ms 36700 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB ok
2 Correct 1 ms 8536 KB ok
3 Correct 1 ms 8540 KB ok
4 Correct 1 ms 6588 KB ok
5 Correct 1 ms 8540 KB ok
6 Correct 1 ms 8540 KB ok
7 Correct 1 ms 8540 KB ok
8 Correct 3 ms 15196 KB ok
9 Correct 24 ms 35188 KB ok
10 Correct 347 ms 152664 KB ok
11 Correct 1 ms 8540 KB ok
12 Correct 1 ms 8540 KB ok
13 Correct 1 ms 8540 KB ok
14 Correct 1 ms 6492 KB ok
15 Correct 1 ms 8536 KB ok
16 Correct 1 ms 8540 KB ok
17 Correct 1 ms 8540 KB ok
18 Correct 1 ms 8540 KB ok
19 Correct 1 ms 8540 KB ok
20 Correct 1 ms 8536 KB ok
21 Correct 1 ms 6492 KB ok
22 Correct 1 ms 8540 KB ok
23 Correct 1 ms 8540 KB ok
24 Correct 1 ms 8540 KB ok
25 Correct 1 ms 8540 KB ok
26 Correct 1 ms 8792 KB ok
27 Correct 1 ms 6492 KB ok
28 Correct 1 ms 6492 KB ok
29 Correct 1 ms 6492 KB ok
30 Correct 1 ms 6492 KB ok
31 Correct 1 ms 6492 KB ok
32 Correct 1 ms 6492 KB ok
33 Correct 2 ms 8540 KB ok
34 Correct 1 ms 6492 KB ok
35 Correct 1 ms 8796 KB ok
36 Correct 1 ms 8796 KB ok
37 Correct 1 ms 8792 KB ok
38 Correct 1 ms 6748 KB ok
39 Correct 1 ms 6748 KB ok
40 Correct 1 ms 6748 KB ok
41 Correct 1 ms 6748 KB ok
42 Correct 1 ms 6748 KB ok
43 Correct 1 ms 6748 KB ok
44 Correct 1 ms 6748 KB ok
45 Correct 2 ms 8540 KB ok
46 Correct 2 ms 8792 KB ok
47 Correct 30 ms 36228 KB ok
48 Correct 28 ms 35984 KB ok
49 Correct 26 ms 36700 KB ok
50 Correct 26 ms 36688 KB ok
51 Correct 27 ms 36404 KB ok
52 Correct 24 ms 35664 KB ok
53 Correct 24 ms 28500 KB ok
54 Correct 24 ms 28504 KB ok
55 Correct 23 ms 30676 KB ok
56 Correct 26 ms 31192 KB ok
57 Correct 22 ms 27228 KB ok
58 Correct 21 ms 26460 KB ok
59 Correct 21 ms 28252 KB ok
60 Correct 21 ms 27740 KB ok
61 Correct 21 ms 30300 KB ok
62 Correct 28 ms 36432 KB ok
63 Correct 26 ms 36472 KB ok
64 Correct 26 ms 36700 KB ok
65 Correct 519 ms 163664 KB ok
66 Correct 360 ms 138368 KB ok
67 Correct 296 ms 130532 KB ok
68 Correct 366 ms 168240 KB ok
69 Correct 431 ms 163012 KB ok
70 Correct 488 ms 162296 KB ok
71 Correct 379 ms 167584 KB ok
72 Correct 352 ms 158544 KB ok
73 Correct 308 ms 140112 KB ok
74 Correct 312 ms 140112 KB ok
75 Correct 345 ms 140556 KB ok
76 Correct 338 ms 147612 KB ok
77 Correct 342 ms 148144 KB ok
78 Correct 397 ms 166284 KB ok
79 Correct 306 ms 129424 KB ok
80 Correct 318 ms 129152 KB ok
81 Correct 294 ms 131632 KB ok
82 Correct 331 ms 136376 KB ok
83 Correct 336 ms 134712 KB ok
84 Correct 273 ms 119336 KB ok
85 Correct 277 ms 116304 KB ok
86 Correct 301 ms 121644 KB ok
87 Correct 315 ms 123432 KB ok
88 Correct 304 ms 132000 KB ok
89 Correct 355 ms 147252 KB ok
90 Correct 336 ms 139296 KB ok
91 Correct 345 ms 148760 KB ok
92 Correct 319 ms 131720 KB ok
93 Correct 313 ms 131480 KB ok
94 Correct 422 ms 130292 KB ok
95 Correct 306 ms 129828 KB ok
96 Correct 285 ms 129440 KB ok
97 Correct 297 ms 128464 KB ok
98 Correct 274 ms 121356 KB ok
99 Correct 483 ms 160628 KB ok
100 Correct 431 ms 167628 KB ok
101 Correct 445 ms 167688 KB ok
102 Correct 440 ms 167696 KB ok
103 Correct 435 ms 168484 KB ok
104 Correct 474 ms 168528 KB ok
105 Correct 465 ms 168372 KB ok
106 Correct 450 ms 167972 KB ok
107 Correct 464 ms 168744 KB ok
108 Correct 350 ms 158856 KB ok
109 Correct 333 ms 159580 KB ok