#include<bits/stdc++.h>
using namespace std;
const int N = 2505;
int n, m, Mnx, 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;
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);
}
}
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);
const int TF = 15;
int Mx_s = 0;
for (int i = 1; i <= min(TF, Mnx); i++)
Mx_s = max(Mx_s, i * Calc(i));
for (int i = Mnx; i >= max(Mnx - TF, 1); i--)
Mx_s = max(Mx_s, i * Calc(i));
int md = max((Mnx + 1 - TF) >> 1, 1);
for (int i = md; i <= min(Mnx, md + TF); i++)
Mx_s = max(Mx_s, i * Calc(i));
return !printf("%d", Mx_s);
}
Compilation message
bomb.cpp: In function 'int main()':
bomb.cpp:87: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:89: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 |
21 ms |
26616 KB |
Output is correct |
4 |
Correct |
21 ms |
26552 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 |
508 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 |
508 KB |
Output is correct |
17 |
Correct |
4 ms |
1016 KB |
Output is correct |
18 |
Correct |
3 ms |
1144 KB |
Output is correct |
19 |
Correct |
7 ms |
1400 KB |
Output is correct |
20 |
Correct |
7 ms |
1400 KB |
Output is correct |
21 |
Correct |
3 ms |
1016 KB |
Output is correct |
22 |
Correct |
4 ms |
1272 KB |
Output is correct |
23 |
Correct |
8 ms |
1528 KB |
Output is correct |
24 |
Correct |
6 ms |
1272 KB |
Output is correct |
25 |
Correct |
8 ms |
1528 KB |
Output is correct |
26 |
Correct |
7 ms |
1528 KB |
Output is correct |
27 |
Correct |
18 ms |
4088 KB |
Output is correct |
28 |
Correct |
40 ms |
4216 KB |
Output is correct |
29 |
Incorrect |
82 ms |
5468 KB |
Output isn't correct |
30 |
Correct |
108 ms |
6392 KB |
Output is correct |
31 |
Incorrect |
87 ms |
5116 KB |
Output isn't correct |
32 |
Correct |
92 ms |
5884 KB |
Output is correct |
33 |
Incorrect |
119 ms |
6780 KB |
Output isn't correct |
34 |
Correct |
40 ms |
4728 KB |
Output is correct |
35 |
Incorrect |
111 ms |
6776 KB |
Output isn't correct |
36 |
Correct |
132 ms |
6744 KB |
Output is correct |
37 |
Correct |
2 ms |
504 KB |
Output is correct |
38 |
Execution timed out |
1075 ms |
57584 KB |
Time limit exceeded |
39 |
Correct |
2 ms |
504 KB |
Output is correct |
40 |
Correct |
467 ms |
16120 KB |
Output is correct |
41 |
Correct |
2 ms |
504 KB |
Output is correct |
42 |
Correct |
9 ms |
1528 KB |
Output is correct |
43 |
Execution timed out |
1081 ms |
57464 KB |
Time limit exceeded |
44 |
Incorrect |
121 ms |
6776 KB |
Output isn't correct |
45 |
Execution timed out |
1085 ms |
57564 KB |
Time limit exceeded |
46 |
Execution timed out |
1077 ms |
57464 KB |
Time limit exceeded |
47 |
Execution timed out |
1067 ms |
57592 KB |
Time limit exceeded |
48 |
Execution timed out |
1079 ms |
57584 KB |
Time limit exceeded |
49 |
Execution timed out |
1075 ms |
57504 KB |
Time limit exceeded |
50 |
Execution timed out |
1066 ms |
57464 KB |
Time limit exceeded |
51 |
Execution timed out |
1084 ms |
57464 KB |
Time limit exceeded |
52 |
Execution timed out |
1077 ms |
57592 KB |
Time limit exceeded |
53 |
Execution timed out |
1076 ms |
57512 KB |
Time limit exceeded |
54 |
Execution timed out |
1063 ms |
57464 KB |
Time limit exceeded |
55 |
Execution timed out |
1062 ms |
57604 KB |
Time limit exceeded |
56 |
Execution timed out |
1066 ms |
57336 KB |
Time limit exceeded |
57 |
Execution timed out |
1087 ms |
57208 KB |
Time limit exceeded |
58 |
Execution timed out |
1074 ms |
56828 KB |
Time limit exceeded |
59 |
Execution timed out |
1076 ms |
56696 KB |
Time limit exceeded |
60 |
Execution timed out |
1069 ms |
56696 KB |
Time limit exceeded |
61 |
Execution timed out |
1086 ms |
56700 KB |
Time limit exceeded |
62 |
Execution timed out |
1080 ms |
56696 KB |
Time limit exceeded |
63 |
Execution timed out |
1077 ms |
56696 KB |
Time limit exceeded |
64 |
Execution timed out |
1075 ms |
56696 KB |
Time limit exceeded |
65 |
Execution timed out |
1078 ms |
56696 KB |
Time limit exceeded |
66 |
Execution timed out |
1080 ms |
56696 KB |
Time limit exceeded |
67 |
Execution timed out |
1085 ms |
56696 KB |
Time limit exceeded |
68 |
Execution timed out |
1076 ms |
56852 KB |
Time limit exceeded |
69 |
Execution timed out |
1087 ms |
56668 KB |
Time limit exceeded |
70 |
Execution timed out |
1078 ms |
45176 KB |
Time limit exceeded |
71 |
Execution timed out |
1084 ms |
56732 KB |
Time limit exceeded |
72 |
Execution timed out |
1083 ms |
56696 KB |
Time limit exceeded |
73 |
Execution timed out |
1066 ms |
56840 KB |
Time limit exceeded |
74 |
Execution timed out |
1076 ms |
56740 KB |
Time limit exceeded |
75 |
Execution timed out |
1086 ms |
56696 KB |
Time limit exceeded |
76 |
Execution timed out |
1084 ms |
56848 KB |
Time limit exceeded |
77 |
Execution timed out |
1091 ms |
56184 KB |
Time limit exceeded |
78 |
Execution timed out |
1088 ms |
56312 KB |
Time limit exceeded |
79 |
Execution timed out |
1087 ms |
56184 KB |
Time limit exceeded |
80 |
Execution timed out |
1089 ms |
56184 KB |
Time limit exceeded |
81 |
Execution timed out |
1082 ms |
56340 KB |
Time limit exceeded |
82 |
Execution timed out |
1089 ms |
56184 KB |
Time limit exceeded |
83 |
Execution timed out |
1076 ms |
56312 KB |
Time limit exceeded |
84 |
Execution timed out |
1085 ms |
56312 KB |
Time limit exceeded |
85 |
Execution timed out |
1102 ms |
56316 KB |
Time limit exceeded |
86 |
Execution timed out |
1085 ms |
56440 KB |
Time limit exceeded |
87 |
Execution timed out |
1082 ms |
56312 KB |
Time limit exceeded |
88 |
Execution timed out |
1076 ms |
56312 KB |
Time limit exceeded |
89 |
Execution timed out |
1080 ms |
56284 KB |
Time limit exceeded |
90 |
Execution timed out |
1077 ms |
45432 KB |
Time limit exceeded |
91 |
Execution timed out |
1076 ms |
56312 KB |
Time limit exceeded |
92 |
Execution timed out |
1065 ms |
56312 KB |
Time limit exceeded |
93 |
Execution timed out |
1075 ms |
56392 KB |
Time limit exceeded |
94 |
Execution timed out |
1071 ms |
56184 KB |
Time limit exceeded |
95 |
Execution timed out |
1066 ms |
56464 KB |
Time limit exceeded |
96 |
Execution timed out |
1082 ms |
56324 KB |
Time limit exceeded |
97 |
Execution timed out |
1083 ms |
56316 KB |
Time limit exceeded |
98 |
Execution timed out |
1087 ms |
56568 KB |
Time limit exceeded |
99 |
Execution timed out |
1075 ms |
56540 KB |
Time limit exceeded |
100 |
Execution timed out |
1080 ms |
56568 KB |
Time limit exceeded |