84562024-01-16 20:15:57bovizdbFestés (50 pont)cpp17Wrong answer 13/50497ms70444 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++)
        {
            v2d dp(n, vll(n));
            for (ll l = 0; l < n; l++)
            {
                for (ll j = 0; j < n-l; j++)
                {
                    if (l == 0 && bitset<4>(b)[j] == 0) dp[j][j] = c[k][j][j];
                    else if (l > 0)
                    {
                        dp[j][j+l] = min(dp[j][j+l-1]+dp[j+1][j+l], c[k][j][j+l]);
                    }
                }
            }
            cost += dp[0][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
base13/50
1Accepted0/03ms1832 KiB
2Wrong answer0/03ms2052 KiB
3Accepted2/2238ms42588 KiB
4Wrong answer0/23ms2164 KiB
5Wrong answer0/37ms2980 KiB
6Accepted2/250ms8976 KiB
7Wrong answer0/2492ms68196 KiB
8Wrong answer0/2488ms68544 KiB
9Wrong answer0/2488ms68508 KiB
10Wrong answer0/2490ms68632 KiB
11Accepted2/2481ms68604 KiB
12Wrong answer0/2449ms63596 KiB
13Wrong answer0/2456ms63808 KiB
14Accepted2/2114ms34656 KiB
15Accepted3/3114ms34792 KiB
16Wrong answer0/3237ms44336 KiB
17Accepted2/2232ms44540 KiB
18Wrong answer0/3236ms44804 KiB
19Wrong answer0/2439ms63212 KiB
20Wrong answer0/2465ms66340 KiB
21Wrong answer0/2476ms68940 KiB
22Wrong answer0/2485ms70116 KiB
23Wrong answer0/2483ms70056 KiB
24Wrong answer0/2485ms70332 KiB
25Wrong answer0/2497ms70444 KiB