답안 #524041

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
524041 2022-02-08T14:43:22 Z boykut Bomb (IZhO17_bomb) C++14
31 / 100
1000 ms 52764 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2500;
int arr[N][N];
int pref[N][N];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n, m;
	cin >> n >> m;
	//if (n * n * n * m * m * m > 1e8) return 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			char x; cin >> x;
			arr[i][j] = x - '0';
			pref[i][j] = x - '0';
			pref[i][j] += (i ? pref[i - 1][j] : 0);
			pref[i][j] += (j ? pref[i][j - 1] : 0);
			pref[i][j] -= (i && j ? pref[i - 1][j - 1] : 0);
		}
	}

	auto get = [&](int a, int b, int c, int d) ->int {
		int s = pref[c][d];
		s -= (a ? pref[a - 1][d] : 0);
		s -= (b ? pref[c][b - 1] : 0);
		s += (a && b ? pref[a - 1][b - 1] : 0);
		return s;
	};

	// brute force

	int Q = 2;
	auto check = [&](int a, int b) ->int {
		for (int i = 0; i + a - 1 < n; i++) {
			for (int j = 0; j + b - 1 < m; j++) {
				int g = get(i, j, i + a - 1, j + b - 1);
				if (g == a * b) {
					for (int i2 = i; i2 <= i + a - 1; i2++) {
						for (int j2 = j; j2 <= j + b - 1; j2++)
							arr[i2][j2] = Q;
					}
				}
			}
		}
		int ok = 1;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (arr[i][j] != 0 && arr[i][j] != Q) ok = 0;
			}
		}
		Q++;
		return ok;
	};

	int ans = 0;
	for (int a = 1; a <= n; a++) {
		int l = 1, r = m;
		while (l < r) {
			int b = (l + r + 1) / 2;
			if (check(a, b))
				l = b;
			else
				r = b - 1;
		}
		if (check(a, l))
			ans = max(ans, a * l);
		// for (int b = l; b <= r; b++) {
		// 	if (check(a, b)) {
		// 		ans = max(ans, a * b);
		// 	}
		// }
	}
	cout << ans << '\n';

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Execution timed out 1085 ms 20300 KB Time limit exceeded
4 Correct 835 ms 20384 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 7 ms 888 KB Output is correct
18 Correct 5 ms 844 KB Output is correct
19 Correct 11 ms 1148 KB Output is correct
20 Correct 17 ms 1100 KB Output is correct
21 Correct 4 ms 716 KB Output is correct
22 Correct 7 ms 996 KB Output is correct
23 Correct 22 ms 1192 KB Output is correct
24 Correct 9 ms 972 KB Output is correct
25 Correct 32 ms 1204 KB Output is correct
26 Correct 366 ms 1208 KB Output is correct
27 Execution timed out 1079 ms 3276 KB Time limit exceeded
28 Correct 448 ms 3612 KB Output is correct
29 Execution timed out 1076 ms 4476 KB Time limit exceeded
30 Execution timed out 1027 ms 5308 KB Time limit exceeded
31 Execution timed out 1064 ms 4296 KB Time limit exceeded
32 Execution timed out 1047 ms 4940 KB Time limit exceeded
33 Execution timed out 1074 ms 5708 KB Time limit exceeded
34 Correct 447 ms 3872 KB Output is correct
35 Execution timed out 1059 ms 5708 KB Time limit exceeded
36 Execution timed out 1072 ms 5624 KB Time limit exceeded
37 Correct 1 ms 452 KB Output is correct
38 Execution timed out 1030 ms 52592 KB Time limit exceeded
39 Correct 1 ms 460 KB Output is correct
40 Execution timed out 1086 ms 14028 KB Time limit exceeded
41 Correct 1 ms 452 KB Output is correct
42 Correct 198 ms 1100 KB Output is correct
43 Execution timed out 1074 ms 52592 KB Time limit exceeded
44 Execution timed out 1091 ms 5712 KB Time limit exceeded
45 Execution timed out 1042 ms 52420 KB Time limit exceeded
46 Execution timed out 1033 ms 51896 KB Time limit exceeded
47 Execution timed out 1058 ms 51908 KB Time limit exceeded
48 Execution timed out 1056 ms 51832 KB Time limit exceeded
49 Execution timed out 1022 ms 51808 KB Time limit exceeded
50 Execution timed out 1088 ms 51984 KB Time limit exceeded
51 Execution timed out 1050 ms 51796 KB Time limit exceeded
52 Execution timed out 1033 ms 51908 KB Time limit exceeded
53 Execution timed out 1046 ms 51908 KB Time limit exceeded
54 Execution timed out 1045 ms 51720 KB Time limit exceeded
55 Execution timed out 1049 ms 51592 KB Time limit exceeded
56 Execution timed out 1065 ms 51316 KB Time limit exceeded
57 Execution timed out 1054 ms 51396 KB Time limit exceeded
58 Execution timed out 1092 ms 51228 KB Time limit exceeded
59 Execution timed out 1054 ms 51008 KB Time limit exceeded
60 Execution timed out 1041 ms 50888 KB Time limit exceeded
61 Execution timed out 1034 ms 51060 KB Time limit exceeded
62 Execution timed out 1080 ms 50824 KB Time limit exceeded
63 Execution timed out 1059 ms 50896 KB Time limit exceeded
64 Execution timed out 1016 ms 50884 KB Time limit exceeded
65 Execution timed out 1088 ms 50876 KB Time limit exceeded
66 Execution timed out 1045 ms 50532 KB Time limit exceeded
67 Execution timed out 1077 ms 50500 KB Time limit exceeded
68 Execution timed out 1052 ms 50700 KB Time limit exceeded
69 Execution timed out 1046 ms 51044 KB Time limit exceeded
70 Execution timed out 1088 ms 40184 KB Time limit exceeded
71 Execution timed out 1060 ms 51380 KB Time limit exceeded
72 Execution timed out 1074 ms 51396 KB Time limit exceeded
73 Execution timed out 1035 ms 51392 KB Time limit exceeded
74 Execution timed out 1067 ms 51400 KB Time limit exceeded
75 Execution timed out 1107 ms 51360 KB Time limit exceeded
76 Execution timed out 1084 ms 51304 KB Time limit exceeded
77 Execution timed out 1056 ms 51444 KB Time limit exceeded
78 Execution timed out 1098 ms 51404 KB Time limit exceeded
79 Execution timed out 1008 ms 51396 KB Time limit exceeded
80 Execution timed out 1022 ms 51452 KB Time limit exceeded
81 Execution timed out 1010 ms 51316 KB Time limit exceeded
82 Execution timed out 1022 ms 51400 KB Time limit exceeded
83 Execution timed out 1075 ms 51392 KB Time limit exceeded
84 Execution timed out 1049 ms 51388 KB Time limit exceeded
85 Execution timed out 1014 ms 51308 KB Time limit exceeded
86 Execution timed out 1041 ms 50372 KB Time limit exceeded
87 Execution timed out 1018 ms 50300 KB Time limit exceeded
88 Execution timed out 1093 ms 50452 KB Time limit exceeded
89 Execution timed out 1029 ms 50740 KB Time limit exceeded
90 Execution timed out 1047 ms 40816 KB Time limit exceeded
91 Execution timed out 1063 ms 51600 KB Time limit exceeded
92 Execution timed out 1060 ms 52200 KB Time limit exceeded
93 Execution timed out 1014 ms 52340 KB Time limit exceeded
94 Execution timed out 1062 ms 52552 KB Time limit exceeded
95 Execution timed out 1058 ms 52760 KB Time limit exceeded
96 Execution timed out 1016 ms 52764 KB Time limit exceeded
97 Execution timed out 1090 ms 52368 KB Time limit exceeded
98 Execution timed out 1026 ms 52000 KB Time limit exceeded
99 Execution timed out 1008 ms 52116 KB Time limit exceeded
100 Execution timed out 1049 ms 52100 KB Time limit exceeded