# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
950688 | Irate | Orchard (NOI14_orchard) | C++17 | 133 ms | 19996 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<cstdio>
#include<vector>
using namespace std;
int main(){
int n, m;
scanf("%d %d", &n, &m);
vector<vector<int>>grid(n + 1, vector<int>(m + 1));
vector<vector<int>>pref(n + 1, vector<int>(m + 1));
for(int i = 1;i <= n;++i){
for(int j = 1;j <= m;++j){
scanf("%d", &grid[i][j]);
pref[i][j] = pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + grid[i][j];
}
}
int res = 1e9, total = pref[n][m];
for(int k = 1;k <= n;++k){
for(int i = 1;i + k - 1 <= n;++i){
int mn = -1;
for(int j = 1;j <= m;++j){
int sum = pref[i + k - 1][j] - pref[i - 1][j];
res = min(res, j * k - 2 * sum + total + k + mn);
mn = min(mn, 2 * sum - k * (j + 1));
}
}
}
printf("%d", res);
}
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... |