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>
using namespace std;
const int mxN = 155;
const int mxM = 1e5 + 5;
int grid[mxN][mxM], pref[mxN][mxM];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
for(int i = 1;i <= n;++i){
for(int j = 1;j <= m;++j){
cin >> grid[i][j];
pref[i][j] = pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + grid[i][j];
}
}
int mn = 1e9;
for(int k = 1;k <= n;++k){
for(int i = 1;i + k - 1 <= n;++i){
set<int>s;
s.insert(-1);
for(int j = 1;j <= m;++j){
auto itr = s.begin();
int sum = pref[i + k - 1][j] - pref[i - 1][j];
mn = min(mn, j * k - 2 * sum + pref[n][m] + k + *itr);
s.insert(2 * (pref[i + k - 1][j] - pref[i - 1][j]) - k * (j + 1));
}
}
}
cout << mn << '\n';
}
# | 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... |