This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define FILE_IO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
//#define int long long
using namespace std;
signed main() {
FAST_IO;
//FILE_IO;
int n, m;
cin >> n >> m;
int grid[n + 1][m + 1];
for (int i = 0; i <= n; i++) grid[i][0] = 0;
for (int i = 0; i <= m; i++) grid[0][i] = 0;
int ones = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> grid[i][j];
if (grid[i][j]) ones++;
else grid[i][j] = -1;
grid[i][j] += grid[i - 1][j];
}
}
int run = 0, maxi = 0;
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
run = 0;
for (int k = 1; k <= m; k++) {
run = max(run + grid[j][k] - grid[i - 1][k], grid[j][k] - grid[i - 1][k]);
if (run < 0) run = 0;
maxi = max(maxi, run);
}
}
}
cout << ones - maxi;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |