107882024-04-12 19:38:05MagyarKendeSZLGFestés (50 pont)cpp17Wrong answer 26/50275ms67716 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define vec vector
int N, M;

ll solve(const vector<bool>& mask, const vec<vec<ll>>& col) {
    vec<ll> dp(N + 1, LLONG_MAX);
    dp[0] = 0;
    for (int j = 1; j <= N; j++) {
        if (mask[j - 1]) {
            dp[j] = dp[j - 1];
        }
        for (int k = 0; k < j; k++) {
            dp[j] = min(dp[j], dp[k] + col[k][j - 1]);
        }
    }
    return dp[N];
}

int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> N >> M;
    vec<ll> rowS(N);
    vec<vec<vec<ll>>> colS(M, vec<vec<ll>>(N, vec<ll>(N)));

    for (int i = 0; i < N; i++) {
        cin >> rowS[i];
    }
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = j; k < N; k++) {
                cin >> colS[i][j][k];
            }
        }
    }

    ll res = LLONG_MAX;
    for (int i = 0; i < (1 << N); i++) {
        ll curr = 0;
        vec<bool> mask(N);
        for (int j = 0; j < N; j++) {
            mask[j] = (i >> j) & 1;
            if (mask[j]) curr += rowS[j];
        }

        for (int j = 0; j < M; j++) {
            curr += solve(mask, colS[j]);
        }

        res = min(res, curr);
    }

    cout << res;
}
SubtaskSumTestVerdictTimeMemory
base26/50
1Accepted0/03ms1828 KiB
2Wrong answer0/03ms2024 KiB
3Accepted2/2143ms40996 KiB
4Wrong answer0/23ms2264 KiB
5Accepted3/34ms3040 KiB
6Wrong answer0/225ms8576 KiB
7Accepted2/2244ms66672 KiB
8Wrong answer0/2245ms66600 KiB
9Wrong answer0/2246ms66596 KiB
10Accepted2/2245ms66724 KiB
11Wrong answer0/2245ms66544 KiB
12Wrong answer0/2225ms61432 KiB
13Wrong answer0/2233ms61300 KiB
14Accepted2/275ms32444 KiB
15Accepted3/376ms32460 KiB
16Accepted3/3136ms41948 KiB
17Accepted2/2136ms41948 KiB
18Accepted3/3137ms42072 KiB
19Accepted2/2219ms60764 KiB
20Wrong answer0/2233ms64136 KiB
21Wrong answer0/2244ms66460 KiB
22Wrong answer0/2247ms67376 KiB
23Wrong answer0/2245ms67496 KiB
24Wrong answer0/2263ms67508 KiB
25Accepted2/2275ms67716 KiB