# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
334192 | juggernaut | Bomb (IZhO17_bomb) | C++14 | 1103 ms | 61804 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int n,m,cnt[2505][2505],pref[2505][2505];
bool a[2505][2505];
char rd(){
char ch;
do{
scanf("%c",&ch);
}while(ch!='0'&&ch!='1');
return ch;
}
bool sum(int x,int y,int x2,int y2){
return (cnt[x2][y2]-cnt[x2][y-1]-cnt[x-1][y2]+cnt[x-1][y-1])==((x2-x+1)*(y2-y+1));
}
void add(int x,int y,int x2,int y2){
x2++,y2++;
pref[x][y]++;
pref[x2][y2]++;
pref[x][y2]--;
pref[x2][y]--;
}
bool check(int x,int y){
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)pref[i][j]=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(sum(i,j,i+x-1,j+y-1))
add(i,j,i+x-1,j+y-1);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
pref[i][j]=pref[i][j]-pref[i-1][j-1]+pref[i][j-1]+pref[i-1][j];
if(a[i][j]&&!pref[i][j])return false;
}
return true;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
a[i][j]=(rd()=='1');
cnt[i][j]=cnt[i-1][j]+cnt[i][j-1]-cnt[i-1][j-1]+a[i][j];
}
int y=m,x=1;
int mx=0;
for(;x<=n;x++){
while(y&&!check(x,y))y--;
mx=max(mx,x*y);
}
printf("%d",mx);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |