60分(样例没过)

P1719 最大加权矩形

zMinYu @ 2023-03-31 18:01:29

#include<bits/stdc++.h>
using namespace std;
const int KKK=3e3+3;
int n,m,q;
long long a[KKK][KKK];
long long ss[KKK][KKK];
int main()
{   
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            scanf("%lld",&a[i][j]);
            ss[i][j]=a[i][j]+ss[i-1][j]+ss[i][j-1]-ss[i-1][j-1];
        }
    }
    long long ans=-0x3f3f3f3f;
    for(int x1=1;x1<=n;x1++)
    for(int x2=1;x2<=n;x2++)
    for(int y1=1;y1<=n;y1++)
    for(int y2=1;y2<=n;y2++)
    ans=max(ans,ss[x2][y2]-ss[x1-1][y2]-ss[x2][y1-1]+ss[x1-1][y1-1]);
    cout<<ans;
    return 0;
}

by zMinYu @ 2023-03-31 18:01:54

WA


by HY248 @ 2023-03-31 18:29:29

for(int x1=1;x1<=n;x1++)
    for(int x2=x1;x2<=n;x2++)
    for(int y1=1;y1<=n;y1++)
    for(int y2=y1;y2<=n;y2++)

注意 x2y2 的初值


by zMinYu @ 2023-04-01 08:20:44

@HY248 谢谢啊!


|