#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
vector<vector<int>> a;
int N, M, sum = 0;
signed main(void)
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
#endif // LOCAL
cin >> N >> M;
a.assign(N + 5, vector<int>(M + 5));
for(int i = 1; i <= N; ++i){
for(int j = 1; j <= M; ++j){
cin >> a[i][j];
sum += a[i][j];
if(a[i][j] == 0) a[i][j] = 1;
else a[i][j] = -1;
}
}
int res = 1e9;
for(int r = 1; r <= N; ++r){
vector<int> col(M + 5, 0);
for(int i = r; i >= 1; --i){
for(int j = 1; j <= M; ++j)
col[j] += a[i][j];
int ps = 0;
int mn = 0;
for(int j = 1; j <= M; ++j){
ps += col[j];
res = min(res, ps - mn);
mn = max(mn, ps);
}
}
}
cout << res + sum;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
768 KB |
Output is correct |
2 |
Correct |
6 ms |
768 KB |
Output is correct |
3 |
Correct |
7 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
29868 KB |
Output is correct |
2 |
Correct |
91 ms |
29740 KB |
Output is correct |
3 |
Correct |
83 ms |
29740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
3824 KB |
Output is correct |
2 |
Correct |
25 ms |
3932 KB |
Output is correct |
3 |
Correct |
21 ms |
3832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
384 KB |
Output is correct |
2 |
Correct |
10 ms |
512 KB |
Output is correct |
3 |
Correct |
12 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
182 ms |
4856 KB |
Output is correct |
2 |
Correct |
179 ms |
4856 KB |
Output is correct |
3 |
Correct |
173 ms |
4856 KB |
Output is correct |