# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
911162 | blackslex | Raisins (IOI09_raisins) | C++17 | 98 ms | 35332 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;
const int N = 55;
int n, m, a[N][N], pref[N][N], dp[N][N][N][N];
int main() {
scanf("%d %d", &n, &m);
for (int ix = 1; ix <= n; ix++) for (int jx = 1; jx <= n; jx++) for (int iy = 1; iy <= m; iy++) for (int jy = 1; jy <= m; jy++) dp[ix][iy][jx][jy] = 1e9;
for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]), pref[i][j] = pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + a[i][j], dp[i][j][i][j] = 0;
for (int szx = 0; szx <= n; szx++) {
for (int szy = 0; szy <= m; szy++) {
if (!szx && !szy) continue;
for (int lx = 1, rx = lx + szx; rx <= n; lx++, rx++) {
for (int ly = 1, ry = ly + szy; ry <= m; ly++, ry++) {
for (int kx = lx; kx < rx; kx++) dp[lx][ly][rx][ry] = min(dp[lx][ly][rx][ry], dp[lx][ly][kx][ry] + dp[kx + 1][ly][rx][ry]);
for (int ky = ly; ky < ry; ky++) dp[lx][ly][rx][ry] = min(dp[lx][ly][rx][ry], dp[lx][ly][rx][ky] + dp[lx][ky + 1][rx][ry]);
dp[lx][ly][rx][ry] += pref[rx][ry] - pref[lx - 1][ry] - pref[rx][ly - 1] + pref[lx - 1][ly - 1];
}
}
}
}
printf("%d", dp[1][1][n][m]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |