#include <bits/stdc++.h>
using namespace std;
#define ar array
#define ll long long
const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
void solve() {
int n, m; cin >> n >> m;
int sum = 0, ps[n + 1][m + 1] = {};
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
char c; cin >> c;
int d = c == '1' ? 1 : -1;
ps[i][j] = ps[i - 1][j] + ps[i][j - 1] - ps[i - 1][j - 1] - d;
sum += c == '1';
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
int mx = 0;
for (int k = 0; k <= m; k++) {
ans = min(ans, ps[j][k] - ps[i - 1][k] - mx);
mx = max(mx, ps[j][k] - ps[i - 1][k]);
}
}
}
cout << ans + sum << "\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int tc = 1;
// cin >> tc;
for (int t = 1; t <= tc; t++) {
// cout << "Case #" << t << ": ";
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
268 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
10240 KB |
Output is correct |
2 |
Correct |
28 ms |
10092 KB |
Output is correct |
3 |
Correct |
32 ms |
10092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1900 KB |
Output is correct |
2 |
Correct |
10 ms |
1900 KB |
Output is correct |
3 |
Correct |
6 ms |
1900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
4 ms |
492 KB |
Output is correct |
3 |
Correct |
4 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
4748 KB |
Output is correct |
2 |
Correct |
114 ms |
4716 KB |
Output is correct |
3 |
Correct |
101 ms |
4716 KB |
Output is correct |