#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
const int N = 2e5 + 5;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n, m, ans = 0;
cin >> n >> m;
vector<vector<int>> a(n + 1, vector<int>(m + 1, 0)), pref(n + 1, vector<int>(m + 1, 0));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
if (a[i][j] == 1) ans--;
else a[i][j] = -1;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) pref[i][j] = pref[i - 1][j] + a[i][j];
}
int mx = 0;
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
int sum = 0;
for (int k = 1; k <= m; k++) {
sum = max(0, sum + pref[j][k] - pref[i - 1][k]);
mx = max(mx, sum);
}
}
}
cout << -1 * (ans + mx) << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
19856 KB |
Output is correct |
2 |
Correct |
53 ms |
19856 KB |
Output is correct |
3 |
Correct |
53 ms |
19884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
3020 KB |
Output is correct |
2 |
Correct |
10 ms |
3404 KB |
Output is correct |
3 |
Correct |
10 ms |
3404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
460 KB |
Output is correct |
3 |
Correct |
3 ms |
456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
101 ms |
6236 KB |
Output is correct |
2 |
Correct |
101 ms |
7648 KB |
Output is correct |
3 |
Correct |
101 ms |
7708 KB |
Output is correct |