6012021-11-04 12:09:46goczbaliDinamitcpp14Wrong answer 35/5048ms3128 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++) {
            for (int x = 0; x <= k; x++) {
                for (int y = 0; y <= k - x; y++) {
                    if (i + 1 < n) {
                        ll c = cost[i + 1][j] / max(2ll * y, 1ll);

                        dp[i + 1][j][x + y] = min(dp[i + 1][j][x + y], dp[i][j][x] + c);
                    }

                    if (j + 1 < n) {
                        ll c = cost[i][j + 1] / max(2ll * y, 1ll);

                        dp[i][j + 1][x + y] = min(dp[i][j + 1][x + y], dp[i][j][x] + c);
                    }
                }
            }
        }
    }

    cout << dp[n - 1][m - 1][k] << endl;
}
SubtaskSumTestVerdictTimeMemory
base35/50
1Accepted0/02ms1800 KiB
2Accepted0/048ms2936 KiB
3Accepted2/22ms1956 KiB
4Accepted2/22ms1980 KiB
5Accepted3/32ms1992 KiB
6Accepted3/32ms2000 KiB
7Accepted2/239ms2988 KiB
8Accepted3/339ms3004 KiB
9Wrong answer0/23ms1980 KiB
10Wrong answer0/23ms1980 KiB
11Wrong answer0/34ms1988 KiB
12Wrong answer0/33ms1992 KiB
13Wrong answer0/210ms2228 KiB
14Wrong answer0/39ms2232 KiB
15Accepted2/239ms3052 KiB
16Accepted3/341ms3060 KiB
17Accepted2/241ms3072 KiB
18Accepted3/339ms3080 KiB
19Accepted2/239ms3092 KiB
20Accepted3/341ms3112 KiB
21Accepted2/241ms3124 KiB
22Accepted3/337ms3128 KiB