#include<iostream>
#include<vector>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> 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){
cin >> 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));
}
}
}
cout << res << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
19992 KB |
Output is correct |
2 |
Correct |
49 ms |
19992 KB |
Output is correct |
3 |
Correct |
49 ms |
19988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
3028 KB |
Output is correct |
2 |
Correct |
10 ms |
3028 KB |
Output is correct |
3 |
Correct |
11 ms |
3028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
648 KB |
Output is correct |
3 |
Correct |
4 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
121 ms |
6368 KB |
Output is correct |
2 |
Correct |
121 ms |
6236 KB |
Output is correct |
3 |
Correct |
121 ms |
6372 KB |
Output is correct |