3542021-10-26 19:29:36goczbaliDinamitcpp14Wrong answer 35/5032ms3224 KiB
#include <iostream>
#include <limits>
#include <vector>

using namespace std;

using ll = long long;

int main() {
    ll n, m, k;
    cin >> n >> m >> k;

    vector<vector<ll>> cost(n, vector<ll>(m));
    for (ll i = 0; i < n; i++) {
        for (ll j = 0; j < m; j++) {
            cin >> cost[i][j];
        }
    }

    vector<vector<vector<ll>>> dp(n, vector<vector<ll>>(m, vector<ll>(k + 1, numeric_limits<ll>::max() / 2 - 1)));

    for (ll i = 0; i <= k; i++) {
        dp[0][0][i] = cost[0][0] / max(2 * i, 1ll);
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (i == 0 && j == 0) {
                continue;
            }

            for (int x = 0; x <= k; x++) {
                for (ll y = 0; x + y <= k; y++) {
                    ll c = cost[i][j] / max(2 * y, 1ll);

                    if (i > 0) {
                        dp[i][j][x + y] = min(dp[i][j][x + y], dp[i - 1][j][x] + c);
                    }

                    if (j > 0) {
                        dp[i][j][x + y] = min(dp[i][j][x + y], dp[i][j - 1][x] + c);
                    }
                }
            }
        }
    }

    cout << dp[n - 1][m - 1][k] << endl;
}
SubtaskSumTestVerdictTimeMemory
base35/50
1Accepted0/02ms1804 KiB
2Accepted0/024ms3024 KiB
3Accepted2/22ms1964 KiB
4Accepted2/22ms1980 KiB
5Accepted3/32ms1988 KiB
6Accepted3/32ms2016 KiB
7Accepted2/223ms3076 KiB
8Accepted3/324ms3092 KiB
9Wrong answer0/23ms1980 KiB
10Wrong answer0/23ms1976 KiB
11Wrong answer0/32ms1988 KiB
12Wrong answer0/33ms1992 KiB
13Wrong answer0/27ms2264 KiB
14Wrong answer0/37ms2252 KiB
15Accepted2/224ms3136 KiB
16Accepted3/324ms3140 KiB
17Accepted2/224ms3160 KiB
18Accepted3/324ms3172 KiB
19Accepted2/232ms3180 KiB
20Accepted3/324ms3196 KiB
21Accepted2/223ms3208 KiB
22Accepted3/324ms3224 KiB