#include <bits/stdc++.h>
#define MAXN 2507
using namespace std;
bool t[MAXN][MAXN],r[MAXN][MAXN];
int p[MAXN][MAXN],d[MAXN][MAXN],n,m,lh,lv;
char s[MAXN][MAXN];
bool provera(int x,int y)
{
for(int i=x;i<=n;i++) for(int j=y;j<=m;j++) r[i][j]=(p[i][j]-p[i-x][j]-p[i][j-y]+p[i-x][j-y]==x*y);
for(int i=n;i>0;i--) for(int j=m;j>0;j--) d[i][j]=r[i][j]+d[i+1][j]+d[i][j+1]-d[i+1][j+1];
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(t[i][j] && d[i][j]-d[min(n+1,i+x)][j]-d[i][min(m+1,j+y)]+d[min(n+1,i+x)][min(m+1,j+y)]==0) return false;
return true;
}
int binarna(int l,int r,int x)
{
if(l==r) return l;
int s=(l+r+1)/2;
if(provera(s,x)) return binarna(s,r,x);
return binarna(l,s-1,x);
}
int najres(int x) {return x*binarna(1,lv,x);}
int main()
{
lh=lv=MAXN;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%s",s[i]);
for(int j=1;j<=m;j++) t[i][j]=(s[i][j-1]=='1'?1:0);
}
for(int i=1;i<=n;i++)
{
int cur=0;
for(int j=1;j<=m;j++)
{
if(t[i][j]==0) {if(cur!=0) lh=min(lh,cur); cur=0;}
else cur++;
}
if(cur!=0) lh=min(lh,cur);
}
for(int i=1;i<=m;i++)
{
int cur=0;
for(int j=1;j<=n;j++)
{
if(t[j][i]==0) {if(cur!=0) lv=min(lv,cur); cur=0;}
else cur++;
}
if(cur!=0) lv=min(lv,cur);
}
int sol=0;
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) p[i][j]=t[i][j]+p[i-1][j]+p[i][j-1]-p[i-1][j-1];
int l=1,r=lh;
/*while(r-l>3)
{
int s1=(2*l+r)/3,s2=(l+2*r)/3;
if(najres(s1)<najres(s2)) l=s1;
else r=s2;
}*/
for(int i=l;i<=r;i++) sol=max(sol,najres(i));
/*for(int i=1;i<=lv;i++)
{
while(!provera(i,lh)) lh--;
if(sol>lh*lv) break;
sol=max(sol,lh*i);
}*/
printf("%d",sol);
}
Compilation message
bomb.cpp: In function 'int main()':
bomb.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
~~~~~^~~~~~~~~~~~~~
bomb.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s",s[i]);
~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
764 KB |
Output is correct |
3 |
Correct |
44 ms |
38840 KB |
Output is correct |
4 |
Correct |
44 ms |
38876 KB |
Output is correct |
5 |
Correct |
2 ms |
38876 KB |
Output is correct |
6 |
Correct |
2 ms |
38876 KB |
Output is correct |
7 |
Correct |
2 ms |
38876 KB |
Output is correct |
8 |
Correct |
2 ms |
38876 KB |
Output is correct |
9 |
Correct |
2 ms |
38876 KB |
Output is correct |
10 |
Correct |
2 ms |
38876 KB |
Output is correct |
11 |
Correct |
2 ms |
38876 KB |
Output is correct |
12 |
Correct |
2 ms |
38876 KB |
Output is correct |
13 |
Correct |
2 ms |
38876 KB |
Output is correct |
14 |
Correct |
3 ms |
38876 KB |
Output is correct |
15 |
Correct |
3 ms |
38876 KB |
Output is correct |
16 |
Correct |
3 ms |
38876 KB |
Output is correct |
17 |
Correct |
4 ms |
38876 KB |
Output is correct |
18 |
Correct |
3 ms |
38876 KB |
Output is correct |
19 |
Correct |
7 ms |
38876 KB |
Output is correct |
20 |
Correct |
7 ms |
38876 KB |
Output is correct |
21 |
Correct |
3 ms |
38876 KB |
Output is correct |
22 |
Correct |
4 ms |
38876 KB |
Output is correct |
23 |
Correct |
11 ms |
38876 KB |
Output is correct |
24 |
Correct |
6 ms |
38876 KB |
Output is correct |
25 |
Correct |
13 ms |
38876 KB |
Output is correct |
26 |
Correct |
7 ms |
38876 KB |
Output is correct |
27 |
Correct |
6 ms |
38876 KB |
Output is correct |
28 |
Correct |
23 ms |
38876 KB |
Output is correct |
29 |
Correct |
474 ms |
38876 KB |
Output is correct |
30 |
Correct |
850 ms |
38876 KB |
Output is correct |
31 |
Correct |
528 ms |
38876 KB |
Output is correct |
32 |
Correct |
326 ms |
38876 KB |
Output is correct |
33 |
Execution timed out |
1070 ms |
38876 KB |
Time limit exceeded |
34 |
Correct |
26 ms |
38876 KB |
Output is correct |
35 |
Correct |
611 ms |
38876 KB |
Output is correct |
36 |
Correct |
247 ms |
38876 KB |
Output is correct |
37 |
Correct |
3 ms |
38876 KB |
Output is correct |
38 |
Execution timed out |
1088 ms |
65020 KB |
Time limit exceeded |
39 |
Correct |
3 ms |
65020 KB |
Output is correct |
40 |
Execution timed out |
1080 ms |
65020 KB |
Time limit exceeded |
41 |
Correct |
3 ms |
65020 KB |
Output is correct |
42 |
Correct |
20 ms |
65020 KB |
Output is correct |
43 |
Execution timed out |
1064 ms |
67516 KB |
Time limit exceeded |
44 |
Execution timed out |
1076 ms |
67516 KB |
Time limit exceeded |
45 |
Execution timed out |
1084 ms |
67516 KB |
Time limit exceeded |
46 |
Execution timed out |
1086 ms |
67964 KB |
Time limit exceeded |
47 |
Execution timed out |
1077 ms |
67964 KB |
Time limit exceeded |
48 |
Execution timed out |
1066 ms |
68092 KB |
Time limit exceeded |
49 |
Correct |
694 ms |
68220 KB |
Output is correct |
50 |
Execution timed out |
1077 ms |
68220 KB |
Time limit exceeded |
51 |
Execution timed out |
1089 ms |
68220 KB |
Time limit exceeded |
52 |
Execution timed out |
1088 ms |
68220 KB |
Time limit exceeded |
53 |
Execution timed out |
1084 ms |
68220 KB |
Time limit exceeded |
54 |
Execution timed out |
1080 ms |
68220 KB |
Time limit exceeded |
55 |
Execution timed out |
1089 ms |
68220 KB |
Time limit exceeded |
56 |
Execution timed out |
1082 ms |
68220 KB |
Time limit exceeded |
57 |
Execution timed out |
1092 ms |
68220 KB |
Time limit exceeded |
58 |
Execution timed out |
1076 ms |
68220 KB |
Time limit exceeded |
59 |
Execution timed out |
1079 ms |
68220 KB |
Time limit exceeded |
60 |
Execution timed out |
1082 ms |
68220 KB |
Time limit exceeded |
61 |
Execution timed out |
1090 ms |
68220 KB |
Time limit exceeded |
62 |
Execution timed out |
1095 ms |
68220 KB |
Time limit exceeded |
63 |
Execution timed out |
1075 ms |
68220 KB |
Time limit exceeded |
64 |
Execution timed out |
1088 ms |
68220 KB |
Time limit exceeded |
65 |
Execution timed out |
1086 ms |
68220 KB |
Time limit exceeded |
66 |
Execution timed out |
1086 ms |
68220 KB |
Time limit exceeded |
67 |
Execution timed out |
1078 ms |
68220 KB |
Time limit exceeded |
68 |
Execution timed out |
1073 ms |
68220 KB |
Time limit exceeded |
69 |
Execution timed out |
1080 ms |
68220 KB |
Time limit exceeded |
70 |
Execution timed out |
1083 ms |
68220 KB |
Time limit exceeded |
71 |
Execution timed out |
1072 ms |
68220 KB |
Time limit exceeded |
72 |
Execution timed out |
1066 ms |
68220 KB |
Time limit exceeded |
73 |
Execution timed out |
1065 ms |
68220 KB |
Time limit exceeded |
74 |
Execution timed out |
1081 ms |
68220 KB |
Time limit exceeded |
75 |
Execution timed out |
1061 ms |
68220 KB |
Time limit exceeded |
76 |
Execution timed out |
1093 ms |
68220 KB |
Time limit exceeded |
77 |
Execution timed out |
1079 ms |
68220 KB |
Time limit exceeded |
78 |
Execution timed out |
1070 ms |
68220 KB |
Time limit exceeded |
79 |
Execution timed out |
1086 ms |
68220 KB |
Time limit exceeded |
80 |
Execution timed out |
1072 ms |
68220 KB |
Time limit exceeded |
81 |
Execution timed out |
1087 ms |
68220 KB |
Time limit exceeded |
82 |
Execution timed out |
1085 ms |
68220 KB |
Time limit exceeded |
83 |
Execution timed out |
1073 ms |
68220 KB |
Time limit exceeded |
84 |
Execution timed out |
1062 ms |
68220 KB |
Time limit exceeded |
85 |
Execution timed out |
1062 ms |
68220 KB |
Time limit exceeded |
86 |
Execution timed out |
1093 ms |
68220 KB |
Time limit exceeded |
87 |
Execution timed out |
1077 ms |
68220 KB |
Time limit exceeded |
88 |
Execution timed out |
1073 ms |
68220 KB |
Time limit exceeded |
89 |
Execution timed out |
1054 ms |
68220 KB |
Time limit exceeded |
90 |
Execution timed out |
1075 ms |
68220 KB |
Time limit exceeded |
91 |
Execution timed out |
1085 ms |
68220 KB |
Time limit exceeded |
92 |
Execution timed out |
1081 ms |
68220 KB |
Time limit exceeded |
93 |
Execution timed out |
1078 ms |
68304 KB |
Time limit exceeded |
94 |
Execution timed out |
1056 ms |
68304 KB |
Time limit exceeded |
95 |
Execution timed out |
1082 ms |
68304 KB |
Time limit exceeded |
96 |
Execution timed out |
1084 ms |
68304 KB |
Time limit exceeded |
97 |
Execution timed out |
1066 ms |
68436 KB |
Time limit exceeded |
98 |
Execution timed out |
1072 ms |
68436 KB |
Time limit exceeded |
99 |
Execution timed out |
1082 ms |
68436 KB |
Time limit exceeded |
100 |
Execution timed out |
1066 ms |
68436 KB |
Time limit exceeded |