# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
265286 | T0p_ | Orchard (NOI14_orchard) | C++14 | 427 ms | 25824 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>
using namespace std;
int dp[155][155][2];
int main()
{
int n, m;
scanf(" %d %d",&n,&m);
int arr[n+5][m+5];
memset(arr, 0, sizeof arr);
for(int i=1 ; i<=n ; i++)
for(int j=1 ; j<=m ; j++)
{
scanf(" %d",&arr[i][j]);
arr[i][j] += arr[i-1][j] + arr[i][j-1] - arr[i-1][j-1];
}
int ans = 1e9;
for(int sz=1 ; sz<=n ; sz++)
for(int i=1 ; i<=n ; i++)
{
int j = i+sz-1;
if(j > n) break ;
for(int k=1 ; k<=m ; k++)
{
dp[i][j][k%2] = min(dp[i][j][(k-1)%2], arr[j][k-1] - arr[i-1][k-1]) + sz - arr[j][k] + arr[j][k-1] + arr[i-1][k] - arr[i-1][k-1];
ans = min(ans, dp[i][j][k%2] + arr[j][m] - arr[j][k] + arr[i-1][k] + arr[n][m] - arr[j][m]);
}
}
printf("%d\n",ans);
return 0;
}
// dp[i][j][k] -> row ith to row jth, col 1st to col kth and end the second area on col kth
/*
5 7
0 0 1 0 0 1 0
0 1 1 1 1 1 0
0 1 1 0 0 1 0
0 1 1 1 1 1 0
0 0 1 0 0 1 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... |