#include <bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> a(n, vector<int>(m, 0));
vector<vector<int>> p(n + 1, vector<int>(m + 1, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
int ans = (int)1e9;
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cnt += a[i][j];
if (a[i][j] == 1) {
a[i][j] = -1;
}
else {
a[i][j] = 1;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
p[i + 1][j + 1] = a[i][j]
+ p[i][j + 1]
+ p[i + 1][j]
- p[i][j];
}
}
for (int x1 = 0; x1 < n; x1++) {
for (int x2 = x1 + 1; x2 < n; x2++) {
vector<int> T(m + 1, 0);
T[m] = p[x2][m] - p[x1][m];
for (int y = m - 1; y >= 0; y--) {
T[y] = min(T[y + 1], p[x2][y] - p[x1][y]);
}
for (int y = 0; y < m; y++) {
int cur = p[x1][y] - p[x2][y] + T[y + 1];
ans = min(ans, cnt + cur);
}
}
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
69 ms |
15892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
2676 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
332 KB |
Output is correct |
2 |
Correct |
11 ms |
460 KB |
Output is correct |
3 |
Correct |
11 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
338 ms |
6212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |