#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';
}
}
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;
for (int i = 1; i <=n; i++) {
int lo = 0;
int ro = m + 1;
while(lo < ro - 1) {
int mid = lo + ro >> 1;
if (check(i, mid)) lo = mid; else ro = mid;
}
ans = max(ans, i * lo);
}
cout << ans << endl;
}
Compilation message
bomb.cpp: In function 'int main()':
bomb.cpp:114:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
114 | int mid = lo + ro >> 1;
| ~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
205 ms |
30432 KB |
Output is correct |
4 |
Correct |
190 ms |
30432 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
308 KB |
Output is correct |
8 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
10 |
Correct |
1 ms |
436 KB |
Output is correct |
11 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
436 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
16 |
Correct |
1 ms |
564 KB |
Output is correct |
17 |
Correct |
11 ms |
1108 KB |
Output is correct |
18 |
Incorrect |
10 ms |
1204 KB |
Output isn't correct |
19 |
Incorrect |
25 ms |
1492 KB |
Output isn't correct |
20 |
Incorrect |
27 ms |
1504 KB |
Output isn't correct |
21 |
Correct |
11 ms |
980 KB |
Output is correct |
22 |
Incorrect |
19 ms |
1236 KB |
Output isn't correct |
23 |
Incorrect |
37 ms |
1620 KB |
Output isn't correct |
24 |
Incorrect |
21 ms |
1364 KB |
Output isn't correct |
25 |
Incorrect |
40 ms |
1620 KB |
Output isn't correct |
26 |
Correct |
38 ms |
1620 KB |
Output is correct |
27 |
Execution timed out |
1086 ms |
4836 KB |
Time limit exceeded |
28 |
Execution timed out |
1088 ms |
5192 KB |
Time limit exceeded |
29 |
Execution timed out |
1082 ms |
6484 KB |
Time limit exceeded |
30 |
Execution timed out |
1089 ms |
7872 KB |
Time limit exceeded |
31 |
Execution timed out |
1089 ms |
6204 KB |
Time limit exceeded |
32 |
Execution timed out |
1090 ms |
7124 KB |
Time limit exceeded |
33 |
Execution timed out |
1074 ms |
8252 KB |
Time limit exceeded |
34 |
Execution timed out |
1092 ms |
5588 KB |
Time limit exceeded |
35 |
Execution timed out |
1087 ms |
8276 KB |
Time limit exceeded |
36 |
Execution timed out |
1093 ms |
8276 KB |
Time limit exceeded |
37 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
38 |
Execution timed out |
1074 ms |
80472 KB |
Time limit exceeded |
39 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
40 |
Execution timed out |
1083 ms |
20544 KB |
Time limit exceeded |
41 |
Correct |
1 ms |
468 KB |
Output is correct |
42 |
Correct |
41 ms |
1596 KB |
Output is correct |
43 |
Execution timed out |
1051 ms |
80352 KB |
Time limit exceeded |
44 |
Execution timed out |
1090 ms |
8276 KB |
Time limit exceeded |
45 |
Execution timed out |
1051 ms |
80460 KB |
Time limit exceeded |
46 |
Execution timed out |
1055 ms |
80412 KB |
Time limit exceeded |
47 |
Execution timed out |
1035 ms |
80348 KB |
Time limit exceeded |
48 |
Execution timed out |
1051 ms |
80420 KB |
Time limit exceeded |
49 |
Execution timed out |
1046 ms |
80388 KB |
Time limit exceeded |
50 |
Execution timed out |
1043 ms |
80460 KB |
Time limit exceeded |
51 |
Execution timed out |
1025 ms |
80384 KB |
Time limit exceeded |
52 |
Execution timed out |
1063 ms |
80384 KB |
Time limit exceeded |
53 |
Execution timed out |
1058 ms |
80404 KB |
Time limit exceeded |
54 |
Execution timed out |
1055 ms |
80380 KB |
Time limit exceeded |
55 |
Execution timed out |
1016 ms |
80420 KB |
Time limit exceeded |
56 |
Execution timed out |
1063 ms |
80580 KB |
Time limit exceeded |
57 |
Execution timed out |
1060 ms |
80576 KB |
Time limit exceeded |
58 |
Execution timed out |
1075 ms |
80532 KB |
Time limit exceeded |
59 |
Execution timed out |
1043 ms |
80480 KB |
Time limit exceeded |
60 |
Execution timed out |
1059 ms |
80524 KB |
Time limit exceeded |
61 |
Execution timed out |
1071 ms |
80588 KB |
Time limit exceeded |
62 |
Execution timed out |
1052 ms |
80540 KB |
Time limit exceeded |
63 |
Execution timed out |
1060 ms |
80832 KB |
Time limit exceeded |
64 |
Execution timed out |
1066 ms |
80972 KB |
Time limit exceeded |
65 |
Execution timed out |
1044 ms |
80708 KB |
Time limit exceeded |
66 |
Execution timed out |
1047 ms |
80624 KB |
Time limit exceeded |
67 |
Execution timed out |
1041 ms |
80644 KB |
Time limit exceeded |
68 |
Execution timed out |
1045 ms |
80672 KB |
Time limit exceeded |
69 |
Execution timed out |
1059 ms |
80536 KB |
Time limit exceeded |
70 |
Execution timed out |
1085 ms |
65148 KB |
Time limit exceeded |
71 |
Execution timed out |
1102 ms |
80360 KB |
Time limit exceeded |
72 |
Execution timed out |
1033 ms |
80252 KB |
Time limit exceeded |
73 |
Execution timed out |
1030 ms |
80288 KB |
Time limit exceeded |
74 |
Execution timed out |
1066 ms |
80320 KB |
Time limit exceeded |
75 |
Execution timed out |
1050 ms |
80236 KB |
Time limit exceeded |
76 |
Execution timed out |
1048 ms |
80344 KB |
Time limit exceeded |
77 |
Execution timed out |
1050 ms |
80388 KB |
Time limit exceeded |
78 |
Execution timed out |
1050 ms |
80244 KB |
Time limit exceeded |
79 |
Execution timed out |
1049 ms |
80428 KB |
Time limit exceeded |
80 |
Execution timed out |
1057 ms |
80272 KB |
Time limit exceeded |
81 |
Execution timed out |
1042 ms |
80272 KB |
Time limit exceeded |
82 |
Execution timed out |
1045 ms |
80240 KB |
Time limit exceeded |
83 |
Execution timed out |
1071 ms |
80176 KB |
Time limit exceeded |
84 |
Execution timed out |
1071 ms |
80000 KB |
Time limit exceeded |
85 |
Execution timed out |
1022 ms |
80036 KB |
Time limit exceeded |
86 |
Execution timed out |
1077 ms |
80020 KB |
Time limit exceeded |
87 |
Execution timed out |
1057 ms |
79876 KB |
Time limit exceeded |
88 |
Execution timed out |
1030 ms |
79840 KB |
Time limit exceeded |
89 |
Execution timed out |
1066 ms |
80032 KB |
Time limit exceeded |
90 |
Execution timed out |
1026 ms |
64676 KB |
Time limit exceeded |
91 |
Execution timed out |
1058 ms |
79764 KB |
Time limit exceeded |
92 |
Execution timed out |
1056 ms |
79864 KB |
Time limit exceeded |
93 |
Execution timed out |
1054 ms |
79908 KB |
Time limit exceeded |
94 |
Execution timed out |
1049 ms |
79712 KB |
Time limit exceeded |
95 |
Execution timed out |
1051 ms |
79824 KB |
Time limit exceeded |
96 |
Execution timed out |
1046 ms |
79808 KB |
Time limit exceeded |
97 |
Execution timed out |
1006 ms |
79652 KB |
Time limit exceeded |
98 |
Execution timed out |
1048 ms |
79544 KB |
Time limit exceeded |
99 |
Execution timed out |
1064 ms |
79448 KB |
Time limit exceeded |
100 |
Execution timed out |
1070 ms |
79428 KB |
Time limit exceeded |