#include<bits/stdc++.h>
using namespace std;
const int maxN = 2600;
int n, m;
int a[maxN][maxN];
int d[maxN][maxN];
int c[maxN][maxN];
string s;
int heuristic() {
int minW = n;
int minH = m;
for (int i = 1; i<=n; i++) {
int cur = 0;
for (int j = 1; j<=m; j++) {
if (a[i][j] == 1) cur++; else {
if (cur > 0) {
minH = min(minH, cur);
cur = 0;
}
}
}
if (cur > 0) minH = min(minH, cur);
}
for (int j = 1; j<=m; j++) {
int cur = 0;
for (int i = 1; i<=n; i++) {
if (a[i][j] == 1) cur++; else {
if (cur > 0) {
minW = min(minW, cur);
cur = 0;
}
}
}
if (cur > 0) minW = min(minW, cur);
}
return minW * minH;
}
int getDSum(int x1, int y1, int x2, int y2) {
if (x2 > n || y2 > m) return 0;
return d[x2][y2] + d[x1 - 1][y1 - 1] - d[x1 - 1][y2] - d[x2][y1 - 1];
}
int getCSum(int x1, int y1, int x2, int y2) {
x1 = max(x1, 1);
y1 = max(y1, 1);
return c[x2][y2] + c[x1 - 1][y1 - 1] - c[x1 - 1][y2] - c[x2][y1 - 1];
}
bool check(int x, int y) {
for (int i = 1; i<=n; i++) {
for (int j = 1; j<=m; j++) {
c[i][j] = 0;
}
}
for (int i = 1; i<=n; i++) {
for (int j = 1; j<=m; j++) {
if (getDSum(i, j, i + x - 1, j + y - 1) == x * y) c[i][j] = 1;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j<=m; j++) {
c[i][j] += c[i - 1][j] + c[i][j - 1] - c[i - 1][j - 1];
}
}
for (int i = 1; i<=n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i][j] && getCSum(i - x + 1, j - y + 1, i, j) == 0) return false;
}
}
return true;
}
int main() {
cin >> n >> m;
for (int i = 1; i <=n; i++) {
cin >> s;
for (int j = 0; j < m; j++) {
a[i][j + 1] = s[j] - '0';
}
}
if (n >= 500 || m >= 500) {
cout << heuristic() << endl;
return 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j<=m; j++) {
d[i][j] = d[i - 1][j] + d[i][j - 1] + a[i][j] - d[i - 1][j - 1];
}
}
int ans = 0;
int width = m;
for (int i = 1; i <=n; i++) {
while (!check(i, width) && width > 0) width--;
ans = max(ans, i * width);
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
244 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
10296 KB |
Output is correct |
4 |
Correct |
5 ms |
10324 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
560 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
432 KB |
Output is correct |
15 |
Correct |
1 ms |
436 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
5 ms |
1164 KB |
Output is correct |
18 |
Correct |
4 ms |
1108 KB |
Output is correct |
19 |
Correct |
8 ms |
1492 KB |
Output is correct |
20 |
Correct |
8 ms |
1492 KB |
Output is correct |
21 |
Correct |
6 ms |
1024 KB |
Output is correct |
22 |
Correct |
10 ms |
1208 KB |
Output is correct |
23 |
Correct |
12 ms |
1620 KB |
Output is correct |
24 |
Correct |
6 ms |
1364 KB |
Output is correct |
25 |
Correct |
13 ms |
1644 KB |
Output is correct |
26 |
Correct |
13 ms |
1644 KB |
Output is correct |
27 |
Correct |
256 ms |
4848 KB |
Output is correct |
28 |
Correct |
418 ms |
5176 KB |
Output is correct |
29 |
Correct |
528 ms |
6572 KB |
Output is correct |
30 |
Correct |
941 ms |
7868 KB |
Output is correct |
31 |
Correct |
693 ms |
6220 KB |
Output is correct |
32 |
Correct |
710 ms |
7244 KB |
Output is correct |
33 |
Execution timed out |
1086 ms |
8276 KB |
Time limit exceeded |
34 |
Correct |
281 ms |
5600 KB |
Output is correct |
35 |
Execution timed out |
1018 ms |
8280 KB |
Time limit exceeded |
36 |
Execution timed out |
1085 ms |
8260 KB |
Time limit exceeded |
37 |
Correct |
1 ms |
468 KB |
Output is correct |
38 |
Correct |
177 ms |
26668 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Incorrect |
19 ms |
7244 KB |
Output isn't correct |
41 |
Correct |
1 ms |
468 KB |
Output is correct |
42 |
Correct |
15 ms |
1620 KB |
Output is correct |
43 |
Correct |
180 ms |
26688 KB |
Output is correct |
44 |
Execution timed out |
1087 ms |
8276 KB |
Time limit exceeded |
45 |
Incorrect |
191 ms |
26772 KB |
Output isn't correct |
46 |
Correct |
181 ms |
26716 KB |
Output is correct |
47 |
Incorrect |
187 ms |
26816 KB |
Output isn't correct |
48 |
Incorrect |
178 ms |
26680 KB |
Output isn't correct |
49 |
Correct |
186 ms |
26776 KB |
Output is correct |
50 |
Incorrect |
181 ms |
26728 KB |
Output isn't correct |
51 |
Incorrect |
190 ms |
26760 KB |
Output isn't correct |
52 |
Incorrect |
186 ms |
26652 KB |
Output isn't correct |
53 |
Incorrect |
176 ms |
26792 KB |
Output isn't correct |
54 |
Incorrect |
182 ms |
26688 KB |
Output isn't correct |
55 |
Incorrect |
177 ms |
26632 KB |
Output isn't correct |
56 |
Correct |
181 ms |
26416 KB |
Output is correct |
57 |
Incorrect |
179 ms |
26448 KB |
Output isn't correct |
58 |
Incorrect |
176 ms |
26532 KB |
Output isn't correct |
59 |
Incorrect |
185 ms |
26544 KB |
Output isn't correct |
60 |
Correct |
174 ms |
26432 KB |
Output is correct |
61 |
Correct |
175 ms |
26400 KB |
Output is correct |
62 |
Correct |
180 ms |
26348 KB |
Output is correct |
63 |
Correct |
170 ms |
26220 KB |
Output is correct |
64 |
Correct |
172 ms |
26188 KB |
Output is correct |
65 |
Incorrect |
175 ms |
26316 KB |
Output isn't correct |
66 |
Incorrect |
173 ms |
26260 KB |
Output isn't correct |
67 |
Incorrect |
174 ms |
26264 KB |
Output isn't correct |
68 |
Incorrect |
179 ms |
26288 KB |
Output isn't correct |
69 |
Incorrect |
171 ms |
26188 KB |
Output isn't correct |
70 |
Incorrect |
112 ms |
20848 KB |
Output isn't correct |
71 |
Incorrect |
179 ms |
26292 KB |
Output isn't correct |
72 |
Incorrect |
173 ms |
26152 KB |
Output isn't correct |
73 |
Incorrect |
177 ms |
26252 KB |
Output isn't correct |
74 |
Incorrect |
174 ms |
26188 KB |
Output isn't correct |
75 |
Incorrect |
176 ms |
26376 KB |
Output isn't correct |
76 |
Incorrect |
175 ms |
26228 KB |
Output isn't correct |
77 |
Incorrect |
186 ms |
26236 KB |
Output isn't correct |
78 |
Incorrect |
178 ms |
26136 KB |
Output isn't correct |
79 |
Incorrect |
174 ms |
26124 KB |
Output isn't correct |
80 |
Incorrect |
177 ms |
25940 KB |
Output isn't correct |
81 |
Incorrect |
178 ms |
26000 KB |
Output isn't correct |
82 |
Incorrect |
174 ms |
25988 KB |
Output isn't correct |
83 |
Incorrect |
176 ms |
25932 KB |
Output isn't correct |
84 |
Incorrect |
184 ms |
25956 KB |
Output isn't correct |
85 |
Incorrect |
171 ms |
25996 KB |
Output isn't correct |
86 |
Incorrect |
172 ms |
26000 KB |
Output isn't correct |
87 |
Incorrect |
173 ms |
26036 KB |
Output isn't correct |
88 |
Incorrect |
177 ms |
25960 KB |
Output isn't correct |
89 |
Incorrect |
173 ms |
25932 KB |
Output isn't correct |
90 |
Incorrect |
116 ms |
20852 KB |
Output isn't correct |
91 |
Incorrect |
173 ms |
25836 KB |
Output isn't correct |
92 |
Incorrect |
172 ms |
25744 KB |
Output isn't correct |
93 |
Incorrect |
176 ms |
25672 KB |
Output isn't correct |
94 |
Incorrect |
177 ms |
25696 KB |
Output isn't correct |
95 |
Incorrect |
175 ms |
25732 KB |
Output isn't correct |
96 |
Incorrect |
174 ms |
25736 KB |
Output isn't correct |
97 |
Incorrect |
175 ms |
25636 KB |
Output isn't correct |
98 |
Incorrect |
178 ms |
25664 KB |
Output isn't correct |
99 |
Incorrect |
173 ms |
25720 KB |
Output isn't correct |
100 |
Incorrect |
176 ms |
25736 KB |
Output isn't correct |