# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
393830 | Berted | Raisins (IOI09_raisins) | C++14 | 426 ms | 34360 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 <iostream>
#define ll long long
using namespace std;
const ll INF = 1e15;
int N, M, pref[51][51];
ll DP[51][51][51][51];
inline int getSum(int y1, int x1, int y2, int x2) {return pref[y2][x2] - pref[y1 - 1][x2] - pref[y2][x1 - 1] + pref[y1 - 1][x1 - 1];}
int main()
{
cin >> N >> M;
for (int i = 1; i <= N; i++)
{
for (int j = 1; j <= M; j++)
{
cin >> pref[i][j];
pref[i][j] += pref[i - 1][j];
pref[i][j] += pref[i][j - 1];
pref[i][j] -= pref[i - 1][j - 1];
}
}
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
if (i == 0 && j == 0) continue;
for (int k = 1; k + i <= N; k++)
{
for (int l = 1; l + j <= M; l++)
{
DP[k][l][k + i][l + j] = INF;
for (int m = k; m < k + i; m++) DP[k][l][k + i][l + j] = min(DP[k][l][k + i][l + j], DP[k][l][m][l + j] + DP[m + 1][l][k + i][l + j]);
for (int m = l; m < l + j; m++) DP[k][l][k + i][l + j] = min(DP[k][l][k + i][l + j], DP[k][l][k + i][m] + DP[k][m + 1][k + i][l + j]);
DP[k][l][k + i][l + j] += getSum(k, l, k + i, l + j);
}
}
}
}
cout << DP[1][1][N][M] << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |