# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1081951 | Dennis_Jason | Raisins (IOI09_raisins) | C++14 | 559 ms | 32344 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 NMAX 2005
#define pb push_back
#define eb emplace_back
#define MOD 100003
#define nl '\n'
#define LLONG_MAX 9223372036854775807
#define pii pair<int,int>
#define tpl tuple<int,int,int>
//#pragma GCC optimize("O3")
using namespace std;
ifstream fin("aib.in");
ofstream fout("aib.out");
/*
*
*
================DEMONSTRATION===================
=====================END========================
*/
int INF =2147483647;
int n,m;
int mat[55][55];
int sp[55][55];
int dp[55][55][55][55];
int suma(int x1, int y1, int x2, int y2) {
return sp[x2][y2] - (x1 > 1 ? sp[x1-1][y2] : 0) - (y1 > 1 ? sp[x2][y1-1] : 0) + (x1 > 1 && y1 > 1 ? sp[x1-1][y1-1] : 0);
}
int solve(int x,int y,int N,int M)
{
if(x==N && y==M)
{
return 0;
}
if(dp[x][y][N][M]!=INF)
return dp[x][y][N][M];
int mini=INF;
//cut on horizontal
for(int i=y;i<M;++i)
{
mini=min(mini,solve(x,i+1,N,M)+solve(x,y,N,i)+suma(x,y,N,M));
}
//cut on vertical
for(int i=x;i<N;++i)
{
mini=min(mini,solve(x,y,i,M)+solve(i+1,y,N,M)+suma(x,y,N,M));
}
return dp[x][y][N][M]=mini;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
for(int i=1;i<=n;++i)
{
for(int j=1;j<=m;++j)
{
cin>>mat[i][j];
}
}
for(int i=1;i<=n;++i)
{
for(int j=1;j<=m;++j)
{
for(int k=1;k<=n;++k)
{
for(int l=1;l<=m;++l)
{
dp[i][j][k][l]=INF;
}
}
}
}
for(int i=1;i<=n;++i)
{
for(int j=1;j<=m;++j)
{
sp[i][j]=sp[i-1][j]+sp[i][j-1]-sp[i-1][j-1]+mat[i][j];
}
}
cout<<solve(1,1,n,m);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |