# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
962583 | starchan | Raisins (IOI09_raisins) | C++17 | 123 ms | 57716 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;
#define int long long
#define in pair<int, int>
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define INF (int)1e17
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
const int MX = 52;
int a[MX][MX];
int dp[MX][MX][MX][MX];
int C(int lx, int rx, int ly, int ry)
{
return a[rx][ry]-a[rx][ly-1]-a[lx-1][ry]+a[lx-1][ly-1];
}
int solve(int lx, int rx, int ly, int ry)
{
if(dp[lx][rx][ly][ry] != -1)
return dp[lx][rx][ly][ry];
int val = INF;
for(int mx = lx; mx < rx; mx++)
val = min(val, solve(lx, mx, ly, ry)+solve(mx+1, rx, ly, ry));
for(int my = ly; my < ry; my++)
val = min(val, solve(lx, rx, ly, my)+solve(lx, rx, my+1, ry));
if(val == INF)
return dp[lx][rx][ly][ry] = 0;
else
return dp[lx][rx][ly][ry] = C(lx, rx, ly, ry)+val;
}
signed main()
{
fast();
int n, m;
cin >> n >> m;
for(auto &i: dp)
for(auto &j: i)
for(auto &k: j)
for(auto &l: k)
l = -1;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
cin >> a[i][j];
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
a[i][j]+=a[i][j-1];
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
a[i][j]+=a[i-1][j];
}
cout << solve(1, n, 1, m) << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |