Description
Analysia
显然的,面积具有二分性
考虑二分面积。
观察数据大小,发现可以直接枚举长。
那就直接枚举喽…
O(n3logn)
Code
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const long long N = 330, M = 330;
long long a[N][M],Sum[N][M],F[N];
long long n,m,Ans;
long long updiv(long long a,long long b)
{
if (a % b == 0) return a / b;
else return (a / b) + 1;
}
bool check(long long S)
{
for (long long x = 1;x <= n;x ++)
{
long long y = updiv(S, x);
for (long long i = 1;i + x - 1 <= n;i ++)
{
for (long long j = 1;j + y - 1 <= m;j ++)
{
long long num = Sum[i + x - 1][j + y - 1] - Sum[i + x - 1][j - 1] - Sum[i - 1][j + y - 1] + Sum[i - 1][j - 1];
if (num > 0) return true;
}
}
}
return false;
}
long long read(long long &n)
{
char ch=' ';long long q=0,w=1;
for(;(ch!='-')&&((ch<'0')||(ch>'9'));ch=getchar());
if(ch=='-')w=-1,ch=getchar();
for(;ch>='0' && ch<='9';ch=getchar())q=q*10+ch-48;n=q*w;return n;
}
int main()
{
//freopen("D:/LiuYuanHao/4820_2.in","r",stdin);
freopen("max.in","r",stdin);freopen("max.out","w",stdout);
read(n),read(m);
for (long long i = 1;i <= n;i ++)
{
for (long long j = 1;j <= m;j ++)
{
read(a[i][j]);
Sum[i][j] = Sum[i][j - 1] + Sum[i - 1][j] - Sum[i - 1][j - 1] + a[i][j];
}
}
long long Le = 0, Ri = n * m, Ans = 0;
/*if (check(Ri / 100))
{
Le = Ri / 100;
}*/
while (Le <= Ri)
{
long long Mid = (Le + Ri) >> 1;
if (check(Mid))
{
Le = Mid + 1;
Ans = Mid;
}
else
Ri = Mid - 1;
}
printf("%lld", Ans);
}