Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
91889 sh25_shenpy 最大子阵_1 C++ 通过 119 MS 1272 KB 952 2026-06-18 06:05:52

Tests(10/10):


#include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 505; int a[N][N]; int s[N]; // 列前缀和压缩 int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> a[i][j]; int max_sum = -1e9; // 枚举上边界 for (int i = 0; i < n; ++i) { memset(s, 0, sizeof(s)); // 枚举下边界 for (int j = i; j < n; ++j) { // 把第 j 行加到列和里 for (int c = 0; c < m; ++c) s[c] += a[j][c]; // Kadane 求最大子段和 int cur = 0; for (int c = 0; c < m; ++c) { cur = max(s[c], cur + s[c]); max_sum = max(max_sum, cur); } } } cout << max_sum << endl; return 0; }


测评信息: