#include<bits/stdc++.h>
using namespace std;
const int N = 2505;
int n, m, Mnx, Mny, R[N], up[N][N], dn[N][N];
int qu[N], F[N];
char A[N][N];
inline int Calc(int lenx)
{
if (lenx > Mnx)
return 0;
int Mn = n;
for (int i = 1; i <= n; i++)
{
int l = 0, r = 0;
for (int j = 1; j <= m; j++)
{
while (r - l && dn[i][j] <= dn[i][qu[r-1]])
r --;
qu[r ++] = j;
if (qu[l] <= j - lenx)
l ++;
F[j - lenx + 1] = dn[i][qu[l]] - 1;
}
l = r = 0;
for (int j = 1; j <= m; j++)
{
while (r - l && up[i][j] >= up[i][qu[r-1]])
r --;
qu[r ++] = j;
if (qu[l] <= j - lenx)
l ++;
F[j - lenx + 1] -= up[i][qu[l]];
}
l = r = 0;
for (int j = 1; j <= m; j++)
{
if (j + lenx - 1 <= m)
{
F[j] = max(F[j], 0);
while (r - l && F[j] >= F[qu[r-1]])
r --;
qu[r ++] = j;
}
while (qu[l] <= j - lenx)
l ++;
if (A[i][j] == '1')
Mn = min(Mn, F[qu[l]]);
}
}
return (Mn);
}
inline void Init()
{
Mnx = m; Mny = n;
for (int i = 1; i <= n; i++)
{
int last = 0;
for (int j = 1; j <= m; j++)
if (A[i][j] == '0')
{
if (last != j - 1)
Mnx = min(Mnx, j - last - 1);
last = j;
}
if (last != m)
Mnx = min(Mnx, m - last);
}
for (int i = 1; i <= m; i++)
{
int last = 0;
for (int j = 1; j <= n; j++)
if (A[j][i] == '0')
{
if (last != j - 1)
Mny = min(Mny, j - last - 1);
last = j;
}
if (last != n)
Mny = min(Mny, n - last);
}
}
void Solve(int l = 1, int r = Mnx)
{
if (r - l + 1 <= 2)
return ;
if (R[l] == R[r])
{
for (int i = l + 1; i < r; i++)
R[i] = R[l];
return ;
}
int md = (l + r) >> 1;
R[md] = Calc(md);
Solve(l, md);
Solve(md, r);
}
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%s", &A[i][1]);
Init();
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
{
up[i][j] = i - 1;
if (A[i - 1][j] == '1')
up[i][j] = up[i - 1][j];
}
for (int i = n; i; i--)
for (int j = 1; j <= m; j++)
{
dn[i][j] = i + 1;
if (A[i + 1][j] == '1')
dn[i][j] = dn[i + 1][j];
if (A[i][j] == '0')
dn[i][j] = 0, up[i][j] = n + 1;
}
R[1] = Calc(1);
R[Mnx] = Calc(Mnx);
Solve(1, Mnx);
int Mx_s = 0;
for (int i = 1; i <= Mnx; i++)
Mx_s = max(Mx_s, i * R[i]);
return !printf("%d", Mx_s);
}
Compilation message
bomb.cpp: In function 'int main()':
bomb.cpp:102:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
bomb.cpp:104:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", &A[i][1]);
~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
18 ms |
26616 KB |
Output is correct |
4 |
Correct |
18 ms |
26616 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
632 KB |
Output is correct |
9 |
Correct |
2 ms |
632 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
508 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
504 KB |
Output is correct |
16 |
Correct |
2 ms |
632 KB |
Output is correct |
17 |
Correct |
2 ms |
1016 KB |
Output is correct |
18 |
Correct |
3 ms |
1144 KB |
Output is correct |
19 |
Correct |
3 ms |
1400 KB |
Output is correct |
20 |
Correct |
3 ms |
1400 KB |
Output is correct |
21 |
Correct |
3 ms |
1016 KB |
Output is correct |
22 |
Correct |
3 ms |
1272 KB |
Output is correct |
23 |
Correct |
4 ms |
1528 KB |
Output is correct |
24 |
Correct |
3 ms |
1272 KB |
Output is correct |
25 |
Correct |
4 ms |
1400 KB |
Output is correct |
26 |
Correct |
3 ms |
1528 KB |
Output is correct |
27 |
Correct |
7 ms |
4088 KB |
Output is correct |
28 |
Correct |
15 ms |
4216 KB |
Output is correct |
29 |
Correct |
89 ms |
5496 KB |
Output is correct |
30 |
Correct |
33 ms |
6440 KB |
Output is correct |
31 |
Correct |
26 ms |
5112 KB |
Output is correct |
32 |
Correct |
25 ms |
5880 KB |
Output is correct |
33 |
Correct |
42 ms |
6648 KB |
Output is correct |
34 |
Correct |
16 ms |
4728 KB |
Output is correct |
35 |
Correct |
39 ms |
6800 KB |
Output is correct |
36 |
Correct |
13 ms |
6776 KB |
Output is correct |
37 |
Correct |
2 ms |
504 KB |
Output is correct |
38 |
Correct |
209 ms |
56952 KB |
Output is correct |
39 |
Correct |
2 ms |
504 KB |
Output is correct |
40 |
Correct |
176 ms |
16120 KB |
Output is correct |
41 |
Correct |
2 ms |
632 KB |
Output is correct |
42 |
Correct |
8 ms |
1528 KB |
Output is correct |
43 |
Correct |
238 ms |
56832 KB |
Output is correct |
44 |
Correct |
427 ms |
6696 KB |
Output is correct |
45 |
Execution timed out |
1080 ms |
56824 KB |
Time limit exceeded |
46 |
Correct |
282 ms |
56824 KB |
Output is correct |
47 |
Execution timed out |
1090 ms |
56824 KB |
Time limit exceeded |
48 |
Execution timed out |
1079 ms |
56696 KB |
Time limit exceeded |
49 |
Correct |
255 ms |
56856 KB |
Output is correct |
50 |
Execution timed out |
1080 ms |
56824 KB |
Time limit exceeded |
51 |
Execution timed out |
1077 ms |
56696 KB |
Time limit exceeded |
52 |
Execution timed out |
1079 ms |
56696 KB |
Time limit exceeded |
53 |
Execution timed out |
1083 ms |
56700 KB |
Time limit exceeded |
54 |
Execution timed out |
1075 ms |
56936 KB |
Time limit exceeded |
55 |
Execution timed out |
1084 ms |
56696 KB |
Time limit exceeded |
56 |
Correct |
277 ms |
56696 KB |
Output is correct |
57 |
Execution timed out |
1073 ms |
56824 KB |
Time limit exceeded |
58 |
Execution timed out |
1068 ms |
56824 KB |
Time limit exceeded |
59 |
Execution timed out |
1082 ms |
56696 KB |
Time limit exceeded |
60 |
Correct |
242 ms |
56824 KB |
Output is correct |
61 |
Correct |
245 ms |
56824 KB |
Output is correct |
62 |
Correct |
220 ms |
56872 KB |
Output is correct |
63 |
Correct |
216 ms |
56740 KB |
Output is correct |
64 |
Correct |
219 ms |
56696 KB |
Output is correct |
65 |
Execution timed out |
1080 ms |
56696 KB |
Time limit exceeded |
66 |
Execution timed out |
1078 ms |
56780 KB |
Time limit exceeded |
67 |
Execution timed out |
1073 ms |
56696 KB |
Time limit exceeded |
68 |
Execution timed out |
1086 ms |
56696 KB |
Time limit exceeded |
69 |
Execution timed out |
1083 ms |
56824 KB |
Time limit exceeded |
70 |
Correct |
770 ms |
45816 KB |
Output is correct |
71 |
Execution timed out |
1091 ms |
56700 KB |
Time limit exceeded |
72 |
Execution timed out |
1084 ms |
56696 KB |
Time limit exceeded |
73 |
Execution timed out |
1089 ms |
56824 KB |
Time limit exceeded |
74 |
Execution timed out |
1071 ms |
56968 KB |
Time limit exceeded |
75 |
Execution timed out |
1089 ms |
56700 KB |
Time limit exceeded |
76 |
Execution timed out |
1084 ms |
56824 KB |
Time limit exceeded |
77 |
Execution timed out |
1070 ms |
56896 KB |
Time limit exceeded |
78 |
Execution timed out |
1090 ms |
56824 KB |
Time limit exceeded |
79 |
Correct |
805 ms |
56852 KB |
Output is correct |
80 |
Correct |
673 ms |
56824 KB |
Output is correct |
81 |
Execution timed out |
1090 ms |
56696 KB |
Time limit exceeded |
82 |
Execution timed out |
1093 ms |
56824 KB |
Time limit exceeded |
83 |
Execution timed out |
1091 ms |
56696 KB |
Time limit exceeded |
84 |
Execution timed out |
1085 ms |
56696 KB |
Time limit exceeded |
85 |
Execution timed out |
1087 ms |
56704 KB |
Time limit exceeded |
86 |
Correct |
1000 ms |
56432 KB |
Output is correct |
87 |
Execution timed out |
1065 ms |
56312 KB |
Time limit exceeded |
88 |
Execution timed out |
1074 ms |
56444 KB |
Time limit exceeded |
89 |
Execution timed out |
1082 ms |
56472 KB |
Time limit exceeded |
90 |
Correct |
835 ms |
45560 KB |
Output is correct |
91 |
Execution timed out |
1082 ms |
56312 KB |
Time limit exceeded |
92 |
Execution timed out |
1079 ms |
56440 KB |
Time limit exceeded |
93 |
Correct |
962 ms |
56440 KB |
Output is correct |
94 |
Execution timed out |
1078 ms |
56312 KB |
Time limit exceeded |
95 |
Execution timed out |
1087 ms |
56312 KB |
Time limit exceeded |
96 |
Execution timed out |
1077 ms |
56448 KB |
Time limit exceeded |
97 |
Correct |
841 ms |
56440 KB |
Output is correct |
98 |
Execution timed out |
1073 ms |
56316 KB |
Time limit exceeded |
99 |
Execution timed out |
1077 ms |
56696 KB |
Time limit exceeded |
100 |
Correct |
989 ms |
56952 KB |
Output is correct |