199782025-12-30 20:21:30KristófFestés (50 pont)cpp17Wrong answer 0/50162ms12276 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M;
    cin >> N >> M;

    vector<long long> R(N);
    for (int i = 0; i < N; i++) cin >> R[i];

    vector<vector<long long>> C(M, vector<long long>(N*(N+1)/2));
    for (int j = 0; j < M; j++)
        for (int k = 0; k < N*(N+1)/2; k++)
            cin >> C[j][k];

    int full = (1 << N) - 1;
    vector<long long> dp(1<<N, LLONG_MAX);
    dp[0] = 0;

    for (int j = 0; j < M; j++) {
        vector<long long> new_dp = dp;
        int idx = 0;
        for (int l = 0; l < N; l++)
            for (int r = l; r < N; r++) {
                int mask = 0;
                for (int i = l; i <= r; i++) mask |= (1 << i);
                for (int s = 0; s < (1<<N); s++) {
                    if (dp[s] != LLONG_MAX) 
                        new_dp[s | mask] = min(new_dp[s | mask], dp[s] + C[j][idx]);
                }
                idx++;
            }
        dp = new_dp;
    }

    for (int i = 0; i < N; i++)
        for (int s = 0; s < (1<<N); s++)
            if (s & (1<<i)) dp[s] = min(dp[s], dp[s ^ (1<<i)] + R[i]);

    cout << dp[full] << "\n";
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/01ms316 KiB
2Wrong answer0/01ms316 KiB
3Wrong answer0/293ms8948 KiB
4Wrong answer0/21ms508 KiB
5Wrong answer0/32ms500 KiB
6Wrong answer0/214ms1468 KiB
7Wrong answer0/2152ms11932 KiB
8Wrong answer0/2157ms12084 KiB
9Wrong answer0/2153ms12176 KiB
10Wrong answer0/2157ms12084 KiB
11Wrong answer0/2156ms12080 KiB
12Wrong answer0/2141ms11052 KiB
13Wrong answer0/2150ms10976 KiB
14Wrong answer0/250ms5684 KiB
15Wrong answer0/350ms5684 KiB
16Wrong answer0/387ms9012 KiB
17Wrong answer0/286ms9012 KiB
18Wrong answer0/386ms8872 KiB
19Wrong answer0/2143ms10804 KiB
20Wrong answer0/2150ms11572 KiB
21Wrong answer0/2152ms11848 KiB
22Wrong answer0/2155ms12084 KiB
23Wrong answer0/2157ms12272 KiB
24Wrong answer0/2155ms12276 KiB
25Wrong answer0/2162ms11932 KiB