# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
516348 | Jomnoi | Orchard (NOI14_orchard) | C++17 | 332 ms | 49172 KiB |
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 DEBUG 0
using namespace std;
const int INF = 1e9 + 7;
vector <vector <int>> a;
vector <int> dp;
int get(int x1, int x2, int y1, int y2) {
return a[x2][y2] - a[x1 - 1][y2] - a[x2][y1 - 1] + a[x1 - 1][y1 - 1];
}
int main() {
int n, m;
scanf(" %d %d", &n, &m);
a.resize(n + 10, vector <int> (m + 10));
dp.resize(m + 10);
int sum = 0;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
scanf(" %d", &a[i][j]);
if(a[i][j] == 0) {
a[i][j] = 1;
}
else {
sum++;
a[i][j] = -1;
}
a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
}
}
int ans = INF;
dp[m + 1] = INF;
for(int i = 1; i <= n; i++) {
for(int j = i; j <= n; j++) {
for(int k = m; k >= 1; k--) {
dp[k] = min(dp[k + 1], get(i, j, 1, k));
}
if(DEBUG) {
cout << "Debugging : " << i << " " << j << endl;
for(int k = 1; k <= m; k++) {
cout << dp[k] << " ";
}
cout << endl;
}
for(int k = 1; k <= m; k++) {
ans = min(ans, sum + dp[k] - get(i, j, 1, k - 1));
}
}
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | 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... |