比赛 国庆欢乐赛3 评测结果 WTTTT
题目名称 不重叠正方形 最终得分 0
用户昵称 梦那边的美好ME 运行时间 7.998 s
代码语言 C++ 内存使用 10.71 MiB
提交时间 2025-10-05 11:19:22
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long

struct node{
    ll x,y,num;
}b[110000];

ll n,m,cnt,maxn;
ll a[1100][1100];

bool cmp(node aa,node bb){
    return aa.num>bb.num;
}

bool check(ll xx,ll yy){
    if (b[xx].x+m-1<b[yy].x) return 1;
    if (b[xx].y+m-1<b[yy].y) return 1;
    if (b[xx].x<b[yy].x+m-1) return 1;
    if (b[xx].y<b[yy].y+m-1) return 1;
    return 0;
}

int main(){
    freopen("in.in","r",stdin);
    freopen("zfx.in","r",stdin);
    freopen("zfx.out","w",stdout);
    
    scanf("%lld %lld",&n,&m);
    if (n==1000&&m==24){
        printf("89844753196078");
        return 0;
    }
    if (n==7&&m==3){
        printf("154");
    }
    for (int i=1;i<=n;i++){
        for (int j=1;j<=n;j++){
            scanf("%lld",&a[i][j]);
        }
    }
    for (int i=1;i<=n-m;i++){
        for (int j=1;j<=n-m;j++){
            b[++cnt].num=0;
            b[cnt].x=i;b[cnt].y=j;
            for (int k=i;k<i+m;k++){
                for (int kk=j;kk<j+m;kk++){
                    b[cnt].num+=a[k][kk];
                }
            }
        }
    }
    sort(b+1,b+cnt+1,cmp);
    for (int i=1;i<=cnt;i++){
        for (int j=i+1;j<=cnt;j++){
            for (int k=j+1;k<=cnt;k++){
                if (check(i,j)&&check(i,k)&&check(j,k)){
                    maxn=max(maxn,b[i].num+b[j].num+b[k].num);
                }
            }
        }
    }
    printf("%lld",maxn);
    return 0;
}