84582024-01-16 20:35:01bovizdbFestés (50 pont)cpp17Wrong answer 6/50273ms70088 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;
                }
                if (bitset<4>(b)[j] == 1) dp[j] = dp[j-1];
                else
                {
                    ll mn = c[k][0][j];
                    for (ll l = 1; l <= j; l++) mn = min(mn, dp[l-1]+c[k][l][j]);
                    dp[j] = mn;
                }
            }
            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
base6/50
1Accepted0/03ms1868 KiB
2Wrong answer0/03ms2088 KiB
3Accepted2/2142ms42824 KiB
4Wrong answer0/23ms2616 KiB
5Wrong answer0/34ms3388 KiB
6Wrong answer0/225ms9412 KiB
7Accepted2/2259ms68748 KiB
8Wrong answer0/2259ms68832 KiB
9Wrong answer0/2240ms68836 KiB
10Wrong answer0/2259ms69056 KiB
11Wrong answer0/2256ms68896 KiB
12Wrong answer0/2236ms63656 KiB
13Wrong answer0/2226ms63700 KiB
14Accepted2/279ms34948 KiB
15Wrong answer0/378ms35116 KiB
16Wrong answer0/3135ms44560 KiB
17Wrong answer0/2137ms44564 KiB
18Wrong answer0/3135ms44768 KiB
19Wrong answer0/2233ms63192 KiB
20Wrong answer0/2246ms66376 KiB
21Wrong answer0/2238ms68960 KiB
22Wrong answer0/2259ms69916 KiB
23Wrong answer0/2238ms70052 KiB
24Wrong answer0/2239ms70088 KiB
25Wrong answer0/2273ms70000 KiB