이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define futaba ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rio return 0;
#define fi first
#define se second
// Fun things are fun. //
int main() {
/* freopen(".txt", "r", stdin);
freopen(".txt", "w", stdout); */
futaba
int n, m;
cin >> n >> m;
int a[n + 5][m + 5], prf[n + 5][m + 5];
int cnt = 0;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
cin >> a[i][j];
if(a[i][j]) cnt++;
}
}
for(int i = 0; i <= n; i++) {
for(int j = 0; j <= m; j++) {
prf[i][j] = 0;
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
prf[i][j] = prf[i - 1][j] + prf[i][j - 1] - prf[i - 1][j - 1];
if(a[i][j]) prf[i][j]++;
}
}
int ans = 1e9;
for(int i = 1; i <= n; i++) {
for(int j = i; j <= n; j++) {
int l = 1;
for(int k = 1; k <= m; k++) {
int tmp = prf[j][k] - prf[j][l - 1] - prf[i - 1][k] + prf[i - 1][l - 1];
if(2 * tmp <= (j - i + 1) * (k - l + 1)) {
l = k + 1;
continue;
}
ans = min(ans, cnt + ((j - i + 1) * (k - l + 1)) - 2 * tmp);
}
}
}
cout << ans << '\n';
rio
}
# | 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... |