1 条题解

  • 1
    @ 2026-2-6 14:40:57

    逆天三分

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    int n,m;
    ll a[310][310],b[310][310],tot[310][310],dp[310];
    ll check(ll k){
    	for(int i=1;i<=n;i++){
    		for(int j=1;j<=m;j++){
    			if(a[i][j]>k)b[i][j]=a[i][j];
    			else b[i][j]=-1e9;
    		}
    	}
    	for(int i=1;i<=n;i++){
    		for(int j=1;j<=m;j++){
    			tot[i][j]=b[i][j]+tot[i-1][j];
    		}
    	}
    	ll ans=0;
    	for(int i1=1;i1<=n;i1++){
    		for(int i2=i1;i2<=n;i2++){
    			dp[0]=0;
    			for(int j=1;j<=m;j++){
    				dp[j]=max(dp[j-1]+tot[i2][j]-tot[i1-1][j],tot[i2][j]-tot[i1-1][j]);
    				ans=max(ans,dp[j]);
    			}
    		}
    	}
    	return ans*(k+1);
    }
    int main(){
    	ios::sync_with_stdio(0);
    	cin.tie(0);
    	cin>>n>>m;
    	for(int i=1;i<=n;i++){
    		for(int j=1;j<=m;j++){
    			cin>>a[i][j];
    		}
    	}
    	int l=0,r=300;
    	while(r-l>10){
    		int mid1=(l+l+r)/3,mid2=(l+r+r)/3;
    		if(check(mid1)<check(mid2))l=mid1;
    		else r=mid2;
    	}
    	ll ans=check(0);
    	for(int i=max(0,l-50);i<=min(300,r+50);i++){
    		ans=max(ans,check(i));
    	}
    	cout<<ans;
    	return 0;
    }
    
    • 1

    信息

    ID
    8897
    时间
    3000ms
    内存
    1024MiB
    难度
    9
    标签
    递交数
    11
    已通过
    6
    上传者