#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);
}
}
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;
}
memset(R, -1, sizeof(R));
R[1] = Calc(1) * 1;
R[Mnx] = Calc(Mnx) * Mnx;
int le = 1, ri = Mnx + 1, md;
while (ri - le > 1)
{
md = (le + ri) >> 1;
if (R[md] == -1) R[md] = Calc(md) * md;
if (R[md-1] == -1) R[md-1] = Calc(md-1) * (md-1);
if (R[md] > R[md-1])
le = md;
else
ri = md;
}
return !printf("%d", R[le]);
}
Compilation message
bomb.cpp: In function 'int main()':
bomb.cpp:72: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:74: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 |
26616 KB |
Output is correct |
4 |
Correct |
21 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 |
436 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 |
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 |
3 ms |
1144 KB |
Output is correct |
19 |
Incorrect |
3 ms |
1400 KB |
Output isn't correct |
20 |
Incorrect |
3 ms |
1400 KB |
Output isn't correct |
21 |
Correct |
2 ms |
888 KB |
Output is correct |
22 |
Correct |
3 ms |
1272 KB |
Output is correct |
23 |
Incorrect |
4 ms |
1528 KB |
Output isn't correct |
24 |
Incorrect |
3 ms |
1272 KB |
Output isn't correct |
25 |
Incorrect |
4 ms |
1528 KB |
Output isn't correct |
26 |
Correct |
4 ms |
1528 KB |
Output is correct |
27 |
Correct |
8 ms |
4088 KB |
Output is correct |
28 |
Correct |
12 ms |
4216 KB |
Output is correct |
29 |
Incorrect |
25 ms |
5372 KB |
Output isn't correct |
30 |
Incorrect |
38 ms |
6544 KB |
Output isn't correct |
31 |
Incorrect |
29 ms |
5112 KB |
Output isn't correct |
32 |
Incorrect |
28 ms |
5884 KB |
Output isn't correct |
33 |
Incorrect |
40 ms |
6800 KB |
Output isn't correct |
34 |
Correct |
12 ms |
4728 KB |
Output is correct |
35 |
Incorrect |
39 ms |
6760 KB |
Output isn't correct |
36 |
Correct |
33 ms |
6904 KB |
Output is correct |
37 |
Correct |
2 ms |
508 KB |
Output is correct |
38 |
Execution timed out |
1073 ms |
57488 KB |
Time limit exceeded |
39 |
Correct |
2 ms |
504 KB |
Output is correct |
40 |
Correct |
181 ms |
16208 KB |
Output is correct |
41 |
Correct |
2 ms |
504 KB |
Output is correct |
42 |
Incorrect |
4 ms |
1532 KB |
Output isn't correct |
43 |
Execution timed out |
1060 ms |
57392 KB |
Time limit exceeded |
44 |
Incorrect |
47 ms |
6776 KB |
Output isn't correct |
45 |
Execution timed out |
1075 ms |
57564 KB |
Time limit exceeded |
46 |
Correct |
917 ms |
57496 KB |
Output is correct |
47 |
Execution timed out |
1075 ms |
57464 KB |
Time limit exceeded |
48 |
Execution timed out |
1071 ms |
57592 KB |
Time limit exceeded |
49 |
Correct |
387 ms |
57464 KB |
Output is correct |
50 |
Execution timed out |
1074 ms |
57464 KB |
Time limit exceeded |
51 |
Execution timed out |
1068 ms |
57464 KB |
Time limit exceeded |
52 |
Execution timed out |
1037 ms |
57496 KB |
Time limit exceeded |
53 |
Execution timed out |
1047 ms |
57592 KB |
Time limit exceeded |
54 |
Execution timed out |
1069 ms |
57464 KB |
Time limit exceeded |
55 |
Correct |
995 ms |
57492 KB |
Output is correct |
56 |
Execution timed out |
1073 ms |
57592 KB |
Time limit exceeded |
57 |
Execution timed out |
1074 ms |
57464 KB |
Time limit exceeded |
58 |
Execution timed out |
1061 ms |
57464 KB |
Time limit exceeded |
59 |
Execution timed out |
1031 ms |
57592 KB |
Time limit exceeded |
60 |
Correct |
731 ms |
57592 KB |
Output is correct |
61 |
Correct |
939 ms |
57512 KB |
Output is correct |
62 |
Execution timed out |
1083 ms |
57464 KB |
Time limit exceeded |
63 |
Execution timed out |
1063 ms |
57464 KB |
Time limit exceeded |
64 |
Execution timed out |
1070 ms |
57464 KB |
Time limit exceeded |
65 |
Correct |
838 ms |
57592 KB |
Output is correct |
66 |
Execution timed out |
1065 ms |
57464 KB |
Time limit exceeded |
67 |
Execution timed out |
1079 ms |
57464 KB |
Time limit exceeded |
68 |
Execution timed out |
1071 ms |
57464 KB |
Time limit exceeded |
69 |
Execution timed out |
1074 ms |
57464 KB |
Time limit exceeded |
70 |
Incorrect |
773 ms |
46072 KB |
Output isn't correct |
71 |
Execution timed out |
1067 ms |
57592 KB |
Time limit exceeded |
72 |
Execution timed out |
1083 ms |
57464 KB |
Time limit exceeded |
73 |
Execution timed out |
1076 ms |
57464 KB |
Time limit exceeded |
74 |
Execution timed out |
1060 ms |
57464 KB |
Time limit exceeded |
75 |
Execution timed out |
1088 ms |
57464 KB |
Time limit exceeded |
76 |
Execution timed out |
1070 ms |
57464 KB |
Time limit exceeded |
77 |
Execution timed out |
1064 ms |
57464 KB |
Time limit exceeded |
78 |
Execution timed out |
1083 ms |
57464 KB |
Time limit exceeded |
79 |
Incorrect |
797 ms |
57616 KB |
Output isn't correct |
80 |
Incorrect |
679 ms |
57592 KB |
Output isn't correct |
81 |
Execution timed out |
1062 ms |
57468 KB |
Time limit exceeded |
82 |
Execution timed out |
1077 ms |
57980 KB |
Time limit exceeded |
83 |
Execution timed out |
1058 ms |
57972 KB |
Time limit exceeded |
84 |
Execution timed out |
1074 ms |
57976 KB |
Time limit exceeded |
85 |
Execution timed out |
1084 ms |
57976 KB |
Time limit exceeded |
86 |
Incorrect |
992 ms |
58120 KB |
Output isn't correct |
87 |
Execution timed out |
1095 ms |
58104 KB |
Time limit exceeded |
88 |
Execution timed out |
1083 ms |
58104 KB |
Time limit exceeded |
89 |
Execution timed out |
1066 ms |
58096 KB |
Time limit exceeded |
90 |
Incorrect |
875 ms |
47080 KB |
Output isn't correct |
91 |
Execution timed out |
1075 ms |
58600 KB |
Time limit exceeded |
92 |
Execution timed out |
1077 ms |
58616 KB |
Time limit exceeded |
93 |
Incorrect |
963 ms |
58744 KB |
Output isn't correct |
94 |
Execution timed out |
1072 ms |
58488 KB |
Time limit exceeded |
95 |
Execution timed out |
1080 ms |
58360 KB |
Time limit exceeded |
96 |
Execution timed out |
1074 ms |
58184 KB |
Time limit exceeded |
97 |
Incorrect |
915 ms |
58356 KB |
Output isn't correct |
98 |
Execution timed out |
1075 ms |
58292 KB |
Time limit exceeded |
99 |
Execution timed out |
1079 ms |
58232 KB |
Time limit exceeded |
100 |
Execution timed out |
1030 ms |
58488 KB |
Time limit exceeded |