#include<bits/stdc++.h>
using namespace std;
const int N = 2550;
int ans;
int x[N];
int n, m, a[N][N];
int s[N][N], H, W;
int f[N][N], bad[N][N];
int dpw[N], dph[N];
char S[N];
inline void press(int i, int j, int h, int w)
{
bad[i][j]++;
bad[i + h][j + w]++;
bad[i + h][j]--;
bad[i][j + w]--;
}
inline bool can(int h, int w)
{
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
bad[i][j] = 0, f[i][j] = 0;
for(int i = 1; i + h - 1 <= n; ++i)
for(int j = 1; j + w - 1 <= m; ++j)
if(s[i + h - 1][j + w - 1] - s[i + h - 1][j - 1] - s[i - 1][j + w - 1] + s[i - 1][j - 1] == h * w)
press(i, j, h, w);
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
{
f[i][j] = f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1] + bad[i][j];
if(a[i][j] == 1 && f[i][j] <= 0)
return false;
}
return true;
}
inline int getw(int h)
{
if(dpw[h] != -1) return dpw[h];
int L = 0, R = W + 1;
while(L + 1 < R)
{
int w = (L + R) >> 1;
if(can(h, w))
L = w;
else
R = w;
}
return dpw[h] = L;
}
inline int geth(int w)
{
if(dph[w] != -1) return dph[w];
int L = 0, R = H + 1;
while(L + 1 < R)
{
int h = (L + R) >> 1;
if(can(h, w))
L = h;
else
R = h;
}
return dph[w] = L;
}
int main()
{
// freopen("bomb.in", "r", stdin);
// freopen("bomb.out", "w", stdout);
scanf("%d%d", &n, &m);
for(int i = 0; i < 2550; ++i)
dpw[i] = dph[i] = -1;
for(int i = 2; i <= n + 1; ++i)
{
scanf("%s\n", S);
for(int j = 2; j <= m + 1; ++j)
a[i][j] = S[j - 2] - '0';
}
n += 2, m += 2;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
H = n, W = m;
for(int i = 1; i <= n; ++i)
{
int cnt = 0;
for(int j = 1; j <= m; ++j)
if(a[i][j] == 1) cnt++;
else
{
if(cnt) W = min(W, cnt);
cnt = 0;
}
}
for(int j = 1; j <= m; ++j)
{
int cnt = 0;
for(int i = 1; i <= n; ++i)
if(a[i][j] == 1) cnt++;
else
{
if(cnt) H = min(H, cnt);
cnt = 0;
}
}
for(int i = 1; i <= H;)
{
int x = getw(i);
int y = geth(x);
ans = max(ans, y * x);
i = y + 1;
}
ans = max(ans, max(W, H));
printf("%d\n", ans);
return 0;
}
Compilation message
bomb.cpp: In function 'int main()':
bomb.cpp:77:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
^
bomb.cpp:83:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s\n", S);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
103648 KB |
Output is correct |
2 |
Correct |
0 ms |
103648 KB |
Output is correct |
3 |
Correct |
6 ms |
103648 KB |
Output is correct |
4 |
Correct |
6 ms |
103648 KB |
Output is correct |
5 |
Correct |
0 ms |
103648 KB |
Output is correct |
6 |
Correct |
0 ms |
103648 KB |
Output is correct |
7 |
Correct |
0 ms |
103648 KB |
Output is correct |
8 |
Correct |
0 ms |
103648 KB |
Output is correct |
9 |
Correct |
0 ms |
103648 KB |
Output is correct |
10 |
Correct |
0 ms |
103648 KB |
Output is correct |
11 |
Correct |
0 ms |
103648 KB |
Output is correct |
12 |
Correct |
0 ms |
103648 KB |
Output is correct |
13 |
Correct |
0 ms |
103648 KB |
Output is correct |
14 |
Correct |
0 ms |
103648 KB |
Output is correct |
15 |
Correct |
0 ms |
103648 KB |
Output is correct |
16 |
Correct |
0 ms |
103648 KB |
Output is correct |
17 |
Correct |
0 ms |
103648 KB |
Output is correct |
18 |
Correct |
0 ms |
103648 KB |
Output is correct |
19 |
Correct |
0 ms |
103648 KB |
Output is correct |
20 |
Correct |
3 ms |
103648 KB |
Output is correct |
21 |
Correct |
0 ms |
103648 KB |
Output is correct |
22 |
Correct |
3 ms |
103648 KB |
Output is correct |
23 |
Correct |
3 ms |
103648 KB |
Output is correct |
24 |
Correct |
0 ms |
103648 KB |
Output is correct |
25 |
Correct |
3 ms |
103648 KB |
Output is correct |
26 |
Correct |
0 ms |
103648 KB |
Output is correct |
27 |
Correct |
3 ms |
103648 KB |
Output is correct |
28 |
Correct |
33 ms |
103648 KB |
Output is correct |
29 |
Correct |
446 ms |
103648 KB |
Output is correct |
30 |
Correct |
56 ms |
103648 KB |
Output is correct |
31 |
Correct |
39 ms |
103648 KB |
Output is correct |
32 |
Correct |
43 ms |
103648 KB |
Output is correct |
33 |
Correct |
76 ms |
103648 KB |
Output is correct |
34 |
Correct |
39 ms |
103648 KB |
Output is correct |
35 |
Correct |
46 ms |
103648 KB |
Output is correct |
36 |
Correct |
19 ms |
103648 KB |
Output is correct |
37 |
Correct |
0 ms |
103648 KB |
Output is correct |
38 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
39 |
Correct |
0 ms |
103648 KB |
Output is correct |
40 |
Correct |
363 ms |
103648 KB |
Output is correct |
41 |
Correct |
0 ms |
103648 KB |
Output is correct |
42 |
Correct |
19 ms |
103648 KB |
Output is correct |
43 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
44 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
45 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
46 |
Correct |
729 ms |
103648 KB |
Output is correct |
47 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
48 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
49 |
Correct |
589 ms |
103648 KB |
Output is correct |
50 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
51 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
52 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
53 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
54 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
55 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
56 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
57 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
58 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
59 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
60 |
Correct |
746 ms |
103648 KB |
Output is correct |
61 |
Correct |
726 ms |
103648 KB |
Output is correct |
62 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
63 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
64 |
Correct |
986 ms |
103648 KB |
Output is correct |
65 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
66 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
67 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
68 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
69 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
70 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
71 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
72 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
73 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
74 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
75 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
76 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
77 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
78 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
79 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
80 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
81 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
82 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
83 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
84 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
85 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
86 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
87 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
88 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
89 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
90 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
91 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
92 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
93 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
94 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
95 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
96 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
97 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
98 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
99 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |
100 |
Execution timed out |
1000 ms |
103648 KB |
Execution timed out |