Submission #207607

# Submission time Handle Problem Language Result Execution time Memory
207607 2020-03-08T05:53:33 Z dolphingarlic Raisins (IOI09_raisins) C++14
100 / 100
372 ms 21112 KB
#include <bits/stdc++.h>
#pragma GCC Optimize("O3")
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;

int dp[51][51][51][51], a[51][51], pref[51][51];

int main() {
    iostream::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    FOR(i, 1, n + 1) FOR(j, 1, m + 1) {
        cin >> a[i][j];
        pref[i][j] = pref[i - 1][j] + pref[i][j - 1] + a[i][j] - pref[i - 1][j - 1];
    }

    FOR(i, 1, n + 1) FOR(j, 1, m + 1) FOR(k, 1, n - i + 2) FOR(l, 1, m - j + 2) {
        if (i == 1 && j == 1) continue;
        int mn = INT_MAX;
        FOR(x, 1, i) mn = min(mn, dp[k][l][x][j] + dp[k + x][l][i - x][j]);
        FOR(x, 1, j) mn = min(mn, dp[k][l][i][x] + dp[k][l + x][i][j - x]);
        dp[k][l][i][j] = mn + pref[k + i - 1][l + j - 1] + pref[k - 1][l - 1] - pref[k + i - 1][l - 1] - pref[k - 1][l + j - 1];
    }

    cout << dp[1][1][n][m];
    return 0;
}

Compilation message

raisins.cpp:2:0: warning: ignoring #pragma GCC Optimize [-Wunknown-pragmas]
 #pragma GCC Optimize("O3")
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 508 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 888 KB Output is correct
7 Correct 5 ms 1016 KB Output is correct
8 Correct 7 ms 2808 KB Output is correct
9 Correct 9 ms 3704 KB Output is correct
10 Correct 11 ms 4472 KB Output is correct
11 Correct 10 ms 3832 KB Output is correct
12 Correct 33 ms 7436 KB Output is correct
13 Correct 52 ms 9440 KB Output is correct
14 Correct 13 ms 4728 KB Output is correct
15 Correct 62 ms 10360 KB Output is correct
16 Correct 9 ms 3576 KB Output is correct
17 Correct 27 ms 7288 KB Output is correct
18 Correct 202 ms 16120 KB Output is correct
19 Correct 297 ms 19576 KB Output is correct
20 Correct 372 ms 21112 KB Output is correct