1 条题解

  • 3
    @ 2023-8-5 9:41:26
    #include<iostream>
    using namespace std;
    const int N = 210;
    long long a[N][N], sum[N][N], ans = -2e18;
    int main(){
        freopen("ring.in","r",stdin);
        freopen("ring.out","w",stdout);
        int n, m;
        cin >> n >> m;
        for (int i = 1; i <= n; i ++){
            for(int j = 1; j <= m; j ++){
                cin >> a[i][j];
                a[n+i][j] = a[i][m+j] = a[n+i][m+j] = a[i][j];
                ans = max(ans, a[i][j]);
            }
        }   
        for (int i = 1; i <= 2*n; i++){
            for (int j = 1; j <= 2*m; j ++){
                sum[i][j] = sum[i-1][j] + a[i][j];
            }
        }
        if(ans <= 0){
            cout << ans << endl;
        }else{
            ans = -0x3f3f3f3f;
            for(int i = 1; i <= n; i ++){
                for (int j = i; j <= 2*n && j-i+1 <= n; j ++){
                    for (int u = 1; u <= m; u ++){
                        long long sumt = 0;
                        for(int k = u; k <= 2*m && k - u + 1 <= m; k ++){
                            sumt += sum[j][k] - sum[i-1][k];
    
                            if(sumt < 0) sumt = 0;
                            ans = max(ans, sumt);
                        }
                    }
    
                }
            }
            cout << ans << endl;
        }
        return 0;
    }
    
    • 1

    信息

    ID
    488
    时间
    1000ms
    内存
    256MiB
    难度
    7
    标签
    (无)
    递交数
    63
    已通过
    14
    上传者