Submission #911162

# Submission time Handle Problem Language Result Execution time Memory
911162 2024-01-18T13:51:54 Z blackslex Raisins (IOI09_raisins) C++17
100 / 100
98 ms 35332 KB
#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

raisins.cpp: In function 'int main()':
raisins.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
raisins.cpp:11:68: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     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;
      |                                                               ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 4536 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 3 ms 12636 KB Output is correct
9 Correct 4 ms 16732 KB Output is correct
10 Correct 5 ms 16732 KB Output is correct
11 Correct 4 ms 14684 KB Output is correct
12 Correct 12 ms 22876 KB Output is correct
13 Correct 20 ms 24924 KB Output is correct
14 Correct 7 ms 14684 KB Output is correct
15 Correct 25 ms 24924 KB Output is correct
16 Correct 6 ms 26972 KB Output is correct
17 Correct 12 ms 29020 KB Output is correct
18 Correct 54 ms 33276 KB Output is correct
19 Correct 85 ms 33284 KB Output is correct
20 Correct 98 ms 35332 KB Output is correct