84632024-01-16 21:12:29bovizdbFestés (50 pont)cpp17Runtime error 0/50152ms69784 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define endl "\n"
#define pll pair<ll, ll>
#define fs first
#define sc second
#define vll vector<ll>
#define v2d vector<vector<ll>>
#define vpll vector<pll>
#define qll queue<ll>
#define stll stack<ll>
#define sll set<ll>
#define mll map<ll, ll>

ll n, m;
vll r;
vector<v2d> c;
int b = 0b0000;


void solve()
{
    cin >> n >> m;
    r.resize(m);
    c.resize(m, v2d(n, vll(n)));
    for (ll i = 0; i < n; i++) cin >> r[i];
    for (ll i = 0; i < m; i++)
    {
        for (ll j = 0; j < n; j++)
        {
            for (ll k = j; k < n; k++) cin >> c[i][j][k];
        }
    }
    ll out = LONG_MAX;
    for (ll i = 0; i < (1<<n); i++)
    {
        ll cost = 0;
        for (ll j = 0; j < n; j++) cost += bitset<4>(b)[j]*r[j];
        for (ll k = 0; k < m; k++)
        {
            vll dp(n);
            for (ll j = 0; j < n; j++)
            {
                if (j == 0)
                {
                    if (bitset<4>(b)[j] == 0) dp[0] = c[k][0][0];
                    continue;
                }
                dp[j] = c[k][0][j];
                ll mn = dp[0];
                for (ll l = j; l >= 1; l++)
                {
                    mn = min(mn, dp[l-1]);
                    dp[j] = min(dp[j], c[k][l][j]+mn);
                }
                if (bitset<4>(b)[j] == 1) dp[j] = min(dp[j-1], dp[j]);
            }
            cost += dp[n-1];
        }
        out = min(out, cost);
        b += 1;
    }
    cout << out;
}
 
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Runtime error0/03ms1920 KiB
2Runtime error0/03ms2212 KiB
3Runtime error0/2101ms43076 KiB
4Runtime error0/23ms2608 KiB
5Runtime error0/34ms3524 KiB
6Runtime error0/217ms9596 KiB
7Runtime error0/2149ms68700 KiB
8Runtime error0/2144ms68956 KiB
9Runtime error0/2144ms69192 KiB
10Runtime error0/2145ms69212 KiB
11Runtime error0/2149ms68976 KiB
12Runtime error0/2131ms63804 KiB
13Runtime error0/2140ms63628 KiB
14Runtime error0/254ms35016 KiB
15Runtime error0/356ms35088 KiB
16Runtime error0/390ms44472 KiB
17Runtime error0/290ms44576 KiB
18Runtime error0/390ms44584 KiB
19Runtime error0/2130ms63012 KiB
20Runtime error0/2140ms66484 KiB
21Runtime error0/2143ms68960 KiB
22Runtime error0/2143ms69724 KiB
23Runtime error0/2143ms69784 KiB
24Runtime error0/2143ms69780 KiB
25Runtime error0/2152ms69780 KiB