# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
88109 | Pajaraja | Bomb (IZhO17_bomb) | C++17 | 1096 ms | 69340 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>
#define MAXN 2507
using namespace std;
bool t[MAXN][MAXN],r[MAXN][MAXN];
int p[MAXN][MAXN],d[MAXN][MAXN],n,m;
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 main()
{
int lh=2507,lv=2507;
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];
for(int i=1;i<=lv;i++)
{
while(!provera(i,lh)) lh--;
if(sol>lh*n) break;
sol=max(sol,lh*i);
}
printf("%d",sol);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |