#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;
}
int Mx_s = 0;
for (int i = 1; i <= m; i++)
Mx_s = max(Mx_s, i * Calc(i));
return !printf("%d", Mx_s);
/*R[1] = Calc(1);
R[Mnx] = Calc(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 |
504 KB |
Output is correct |
3 |
Correct |
18 ms |
26492 KB |
Output is correct |
4 |
Correct |
18 ms |
26488 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 |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
504 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 |
504 KB |
Output is correct |
17 |
Correct |
3 ms |
1016 KB |
Output is correct |
18 |
Correct |
2 ms |
1144 KB |
Output is correct |
19 |
Correct |
4 ms |
1400 KB |
Output is correct |
20 |
Correct |
4 ms |
1400 KB |
Output is correct |
21 |
Correct |
2 ms |
888 KB |
Output is correct |
22 |
Correct |
3 ms |
1272 KB |
Output is correct |
23 |
Correct |
6 ms |
1400 KB |
Output is correct |
24 |
Correct |
4 ms |
1272 KB |
Output is correct |
25 |
Correct |
6 ms |
1400 KB |
Output is correct |
26 |
Correct |
4 ms |
1400 KB |
Output is correct |
27 |
Correct |
8 ms |
4088 KB |
Output is correct |
28 |
Correct |
15 ms |
4344 KB |
Output is correct |
29 |
Correct |
126 ms |
5500 KB |
Output is correct |
30 |
Correct |
285 ms |
6444 KB |
Output is correct |
31 |
Correct |
191 ms |
5112 KB |
Output is correct |
32 |
Correct |
108 ms |
5904 KB |
Output is correct |
33 |
Correct |
334 ms |
6772 KB |
Output is correct |
34 |
Correct |
16 ms |
4752 KB |
Output is correct |
35 |
Correct |
322 ms |
6776 KB |
Output is correct |
36 |
Correct |
71 ms |
6648 KB |
Output is correct |
37 |
Correct |
2 ms |
504 KB |
Output is correct |
38 |
Execution timed out |
1059 ms |
58104 KB |
Time limit exceeded |
39 |
Correct |
2 ms |
504 KB |
Output is correct |
40 |
Execution timed out |
1067 ms |
16252 KB |
Time limit exceeded |
41 |
Correct |
2 ms |
508 KB |
Output is correct |
42 |
Correct |
8 ms |
1528 KB |
Output is correct |
43 |
Execution timed out |
1073 ms |
58120 KB |
Time limit exceeded |
44 |
Correct |
528 ms |
6904 KB |
Output is correct |
45 |
Execution timed out |
1069 ms |
58104 KB |
Time limit exceeded |
46 |
Execution timed out |
1074 ms |
58104 KB |
Time limit exceeded |
47 |
Execution timed out |
1087 ms |
58060 KB |
Time limit exceeded |
48 |
Execution timed out |
1089 ms |
58076 KB |
Time limit exceeded |
49 |
Correct |
424 ms |
58232 KB |
Output is correct |
50 |
Execution timed out |
1086 ms |
58104 KB |
Time limit exceeded |
51 |
Execution timed out |
1089 ms |
58104 KB |
Time limit exceeded |
52 |
Execution timed out |
1077 ms |
58108 KB |
Time limit exceeded |
53 |
Execution timed out |
1061 ms |
58232 KB |
Time limit exceeded |
54 |
Execution timed out |
1073 ms |
58104 KB |
Time limit exceeded |
55 |
Execution timed out |
1083 ms |
58104 KB |
Time limit exceeded |
56 |
Execution timed out |
1095 ms |
58104 KB |
Time limit exceeded |
57 |
Execution timed out |
1090 ms |
58104 KB |
Time limit exceeded |
58 |
Execution timed out |
1070 ms |
58232 KB |
Time limit exceeded |
59 |
Execution timed out |
1090 ms |
58104 KB |
Time limit exceeded |
60 |
Execution timed out |
1078 ms |
58104 KB |
Time limit exceeded |
61 |
Execution timed out |
1086 ms |
58104 KB |
Time limit exceeded |
62 |
Execution timed out |
1082 ms |
58104 KB |
Time limit exceeded |
63 |
Execution timed out |
1075 ms |
57848 KB |
Time limit exceeded |
64 |
Execution timed out |
1082 ms |
57848 KB |
Time limit exceeded |
65 |
Execution timed out |
1066 ms |
58040 KB |
Time limit exceeded |
66 |
Execution timed out |
1075 ms |
57848 KB |
Time limit exceeded |
67 |
Execution timed out |
1076 ms |
57852 KB |
Time limit exceeded |
68 |
Execution timed out |
1077 ms |
57848 KB |
Time limit exceeded |
69 |
Execution timed out |
1076 ms |
57848 KB |
Time limit exceeded |
70 |
Execution timed out |
1080 ms |
45816 KB |
Time limit exceeded |
71 |
Execution timed out |
1077 ms |
57848 KB |
Time limit exceeded |
72 |
Execution timed out |
1080 ms |
57976 KB |
Time limit exceeded |
73 |
Execution timed out |
1072 ms |
57848 KB |
Time limit exceeded |
74 |
Execution timed out |
1074 ms |
57764 KB |
Time limit exceeded |
75 |
Execution timed out |
1080 ms |
57720 KB |
Time limit exceeded |
76 |
Execution timed out |
1085 ms |
57712 KB |
Time limit exceeded |
77 |
Execution timed out |
1078 ms |
57720 KB |
Time limit exceeded |
78 |
Execution timed out |
1078 ms |
57592 KB |
Time limit exceeded |
79 |
Execution timed out |
1081 ms |
57468 KB |
Time limit exceeded |
80 |
Execution timed out |
1067 ms |
57304 KB |
Time limit exceeded |
81 |
Execution timed out |
1065 ms |
57384 KB |
Time limit exceeded |
82 |
Execution timed out |
1075 ms |
57336 KB |
Time limit exceeded |
83 |
Execution timed out |
1082 ms |
57464 KB |
Time limit exceeded |
84 |
Execution timed out |
1085 ms |
57336 KB |
Time limit exceeded |
85 |
Execution timed out |
1073 ms |
57336 KB |
Time limit exceeded |
86 |
Execution timed out |
1081 ms |
57336 KB |
Time limit exceeded |
87 |
Execution timed out |
1072 ms |
57336 KB |
Time limit exceeded |
88 |
Execution timed out |
1087 ms |
57336 KB |
Time limit exceeded |
89 |
Execution timed out |
1087 ms |
57208 KB |
Time limit exceeded |
90 |
Execution timed out |
1089 ms |
45740 KB |
Time limit exceeded |
91 |
Execution timed out |
1074 ms |
57336 KB |
Time limit exceeded |
92 |
Execution timed out |
1070 ms |
57340 KB |
Time limit exceeded |
93 |
Execution timed out |
1083 ms |
57344 KB |
Time limit exceeded |
94 |
Execution timed out |
1085 ms |
57208 KB |
Time limit exceeded |
95 |
Execution timed out |
1084 ms |
57268 KB |
Time limit exceeded |
96 |
Execution timed out |
1088 ms |
56952 KB |
Time limit exceeded |
97 |
Execution timed out |
1093 ms |
57080 KB |
Time limit exceeded |
98 |
Execution timed out |
1079 ms |
56952 KB |
Time limit exceeded |
99 |
Execution timed out |
1086 ms |
57080 KB |
Time limit exceeded |
100 |
Execution timed out |
1091 ms |
57208 KB |
Time limit exceeded |