#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 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 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);
}
int ans = 0;
for (int i = 0; i< min(3, minW); i++) {
for (int j = 0; j<min(3, minH); j++) {
if (check(minW - i, minH -j)) ans = max(ans, (minW - i) * (minH -j));
}
}
return ans;
}
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 (width > 0 && !check(i, width)) width--;
ans = max(ans, i * width);
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
564 KB |
Output is correct |
3 |
Incorrect |
13 ms |
20404 KB |
Output isn't correct |
4 |
Incorrect |
13 ms |
20428 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
7 |
Correct |
1 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
568 KB |
Output is correct |
10 |
Correct |
1 ms |
428 KB |
Output is correct |
11 |
Correct |
1 ms |
564 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
432 KB |
Output is correct |
14 |
Correct |
1 ms |
432 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
5 ms |
1108 KB |
Output is correct |
18 |
Correct |
4 ms |
1108 KB |
Output is correct |
19 |
Correct |
6 ms |
1492 KB |
Output is correct |
20 |
Correct |
7 ms |
1492 KB |
Output is correct |
21 |
Correct |
4 ms |
952 KB |
Output is correct |
22 |
Correct |
6 ms |
1236 KB |
Output is correct |
23 |
Correct |
11 ms |
1644 KB |
Output is correct |
24 |
Correct |
6 ms |
1332 KB |
Output is correct |
25 |
Correct |
11 ms |
1620 KB |
Output is correct |
26 |
Correct |
9 ms |
1648 KB |
Output is correct |
27 |
Correct |
149 ms |
4844 KB |
Output is correct |
28 |
Correct |
274 ms |
5176 KB |
Output is correct |
29 |
Correct |
378 ms |
6576 KB |
Output is correct |
30 |
Correct |
893 ms |
7864 KB |
Output is correct |
31 |
Correct |
609 ms |
6224 KB |
Output is correct |
32 |
Correct |
551 ms |
7148 KB |
Output is correct |
33 |
Correct |
837 ms |
8284 KB |
Output is correct |
34 |
Correct |
146 ms |
5588 KB |
Output is correct |
35 |
Correct |
612 ms |
8284 KB |
Output is correct |
36 |
Correct |
759 ms |
8280 KB |
Output is correct |
37 |
Correct |
1 ms |
468 KB |
Output is correct |
38 |
Incorrect |
607 ms |
52448 KB |
Output isn't correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Incorrect |
66 ms |
13880 KB |
Output isn't correct |
41 |
Correct |
2 ms |
468 KB |
Output is correct |
42 |
Correct |
12 ms |
1620 KB |
Output is correct |
43 |
Incorrect |
616 ms |
52468 KB |
Output isn't correct |
44 |
Execution timed out |
1068 ms |
8288 KB |
Time limit exceeded |
45 |
Incorrect |
544 ms |
52504 KB |
Output isn't correct |
46 |
Incorrect |
569 ms |
52456 KB |
Output isn't correct |
47 |
Incorrect |
590 ms |
52484 KB |
Output isn't correct |
48 |
Incorrect |
599 ms |
52504 KB |
Output isn't correct |
49 |
Incorrect |
585 ms |
52496 KB |
Output isn't correct |
50 |
Incorrect |
575 ms |
52508 KB |
Output isn't correct |
51 |
Incorrect |
564 ms |
52624 KB |
Output isn't correct |
52 |
Incorrect |
777 ms |
52424 KB |
Output isn't correct |
53 |
Incorrect |
600 ms |
52456 KB |
Output isn't correct |
54 |
Incorrect |
606 ms |
52488 KB |
Output isn't correct |
55 |
Incorrect |
653 ms |
52464 KB |
Output isn't correct |
56 |
Incorrect |
614 ms |
51600 KB |
Output isn't correct |
57 |
Incorrect |
568 ms |
51228 KB |
Output isn't correct |
58 |
Incorrect |
561 ms |
51232 KB |
Output isn't correct |
59 |
Incorrect |
587 ms |
51232 KB |
Output isn't correct |
60 |
Incorrect |
656 ms |
51232 KB |
Output isn't correct |
61 |
Incorrect |
617 ms |
51228 KB |
Output isn't correct |
62 |
Incorrect |
575 ms |
51228 KB |
Output isn't correct |
63 |
Incorrect |
588 ms |
51232 KB |
Output isn't correct |
64 |
Incorrect |
552 ms |
51232 KB |
Output isn't correct |
65 |
Incorrect |
587 ms |
51228 KB |
Output isn't correct |
66 |
Incorrect |
562 ms |
51232 KB |
Output isn't correct |
67 |
Incorrect |
561 ms |
51152 KB |
Output isn't correct |
68 |
Incorrect |
574 ms |
51232 KB |
Output isn't correct |
69 |
Incorrect |
555 ms |
51272 KB |
Output isn't correct |
70 |
Incorrect |
427 ms |
41056 KB |
Output isn't correct |
71 |
Incorrect |
557 ms |
51304 KB |
Output isn't correct |
72 |
Incorrect |
574 ms |
51228 KB |
Output isn't correct |
73 |
Incorrect |
530 ms |
51232 KB |
Output isn't correct |
74 |
Incorrect |
625 ms |
51228 KB |
Output isn't correct |
75 |
Incorrect |
571 ms |
51336 KB |
Output isn't correct |
76 |
Incorrect |
543 ms |
51152 KB |
Output isn't correct |
77 |
Incorrect |
540 ms |
51284 KB |
Output isn't correct |
78 |
Incorrect |
550 ms |
51228 KB |
Output isn't correct |
79 |
Incorrect |
555 ms |
51232 KB |
Output isn't correct |
80 |
Incorrect |
553 ms |
51236 KB |
Output isn't correct |
81 |
Incorrect |
586 ms |
51232 KB |
Output isn't correct |
82 |
Incorrect |
550 ms |
51232 KB |
Output isn't correct |
83 |
Incorrect |
566 ms |
51220 KB |
Output isn't correct |
84 |
Incorrect |
573 ms |
51228 KB |
Output isn't correct |
85 |
Incorrect |
558 ms |
51232 KB |
Output isn't correct |
86 |
Incorrect |
599 ms |
51264 KB |
Output isn't correct |
87 |
Incorrect |
547 ms |
51232 KB |
Output isn't correct |
88 |
Incorrect |
654 ms |
51232 KB |
Output isn't correct |
89 |
Incorrect |
562 ms |
51148 KB |
Output isn't correct |
90 |
Incorrect |
383 ms |
41036 KB |
Output isn't correct |
91 |
Incorrect |
553 ms |
51152 KB |
Output isn't correct |
92 |
Incorrect |
560 ms |
51228 KB |
Output isn't correct |
93 |
Incorrect |
561 ms |
51148 KB |
Output isn't correct |
94 |
Incorrect |
552 ms |
51228 KB |
Output isn't correct |
95 |
Incorrect |
597 ms |
51164 KB |
Output isn't correct |
96 |
Incorrect |
567 ms |
51232 KB |
Output isn't correct |
97 |
Incorrect |
566 ms |
51228 KB |
Output isn't correct |
98 |
Incorrect |
550 ms |
51148 KB |
Output isn't correct |
99 |
Incorrect |
577 ms |
51192 KB |
Output isn't correct |
100 |
Incorrect |
577 ms |
51232 KB |
Output isn't correct |