description
analysis
-
容易想到把原矩阵翻转(45°),然后每个数再用(0)隔开
-
然后就变成了求最大子正方形,求完二维前缀和之后就很好做了
code
#pragma GCC optimize("O3")
#pragma G++ optimize("O3")
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define MAXN 6005
#define ha 19260817
#define ll long long
#define reg register ll
#define fo(i,a,b) for (reg i=a;i<=b;++i)
#define fd(i,a,b) for (reg i=a;i>=b;--i)
using namespace std;
ll a[3005][3005],b[MAXN][MAXN];
ll n,m,h,type,ans=-ha;
ll Seed,A,B,C,MOD;
inline ll read()
{
ll x=0,f=1;char ch=getchar();
while (ch<'0' || '9'<ch){if (ch='-')f=-1;ch=getchar();}
while ('0'<=ch && ch<='9')x=x*10+ch-'0',ch=getchar();
return x*f;
}
inline ll max(ll x,ll y){return x>y?x:y;}
inline ll Random(){C++,Seed=(Seed*A+B*C)%MOD;return Seed;}
inline ll Random_int(){ll tmp=Random();if (Random()&1)tmp*=-1;return tmp;}
inline ll calc(ll x,ll y,ll xx,ll yy){return b[xx][yy]-b[x-1][yy]-b[xx][y-1]+b[x-1][y-1];}
int main()
{
//freopen("T1.in","r",stdin);
freopen("rhombus.in","r",stdin);
freopen("rhombus.out","w",stdout);
n=read(),m=read(),h=read(),type=read();
if (type)
{
Seed=read(),A=read(),B=read(),C=read(),MOD=read();
fo(i,1,n)fo(j,1,m)a[i][j]=Random_int();
}
else {fo(i,1,n)fo(j,1,m)a[i][j]=read();}
fo(i,1,n)fo(j,1,m)b[i-j+m][i+j]=a[i][j];
fo(i,1,n+m)fo(j,1,n+m)b[i][j]+=b[i-1][j]+b[i][j-1]-b[i-1][j-1];
fo(i,1,n+m)for (reg j=((m-i)&1)?1:0;j<=n+m;j+=2)
{
ll tmpx=(i+j-m)/2,tmpy=j-tmpx;
if (h<=tmpx && tmpx<=n-h+1 && h<=tmpy && tmpy<=m-h+1)ans=max(ans,calc(i-h+1,j-h+1,i+h-1,j+h-1));
}
printf("%lld
",ans);
return 0;
}