205032026-01-07 13:18:06szabelrFestés (50 pont)cpp17Wrong answer 26/50185ms10208 KiB
// Festés_clean.c=pp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <climits>
using namespace std;
int ar[100001][5][5];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    vector<int>sorar(n);
    for (int i = 0; i < n; i++)
    {
        int x; cin >> x;
        sorar[i] = x;
    }
    //m,kezdet,veg
    for (int i = 1; i <= m; i++)
    {
        for (int y = 1; y <= n; y++)
        {
            for (int z = y; z <= n; z++)
            {
                int x; cin >> x;
                ar[i][y][z] = x;
            }
        }
    }
    long long best_sum = 1e18;
    for (int bitmask = 0; bitmask <= (1 << n)-1; bitmask++)
    {
        long long sum = 0;
        for (int j = 0; j <= n - 1; j++)
        {
            if ((bitmask & (1 << j)) != 0)
                sum += sorar[j];
        }
        for (int i = 1; i <= m; i++)
        {
            vector<long long>dp(n + 1, 1e18);
            dp[0] = 0;
            for (int y = 1; y <= n; y++)
            {
                if ((bitmask & (1 << (y - 1))) != 0)
                    dp[y] = min(dp[y - 1],dp[y]);
                for (int z = 1; z <= y; z++)
                {
                   
                    dp[y] = min(dp[y], ar[i][z][y] + dp[z - 1]);
                    
                 }
                
            }
            sum += dp[n];
        }
        best_sum = min(best_sum, sum);
    }
    cout << best_sum;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base26/50
1Accepted0/01ms520 KiB
2Wrong answer0/01ms316 KiB
3Accepted2/2103ms10036 KiB
4Wrong answer0/21ms316 KiB
5Accepted3/33ms316 KiB
6Wrong answer0/217ms1332 KiB
7Accepted2/2175ms10116 KiB
8Wrong answer0/2179ms10036 KiB
9Wrong answer0/2177ms10092 KiB
10Accepted2/2179ms10036 KiB
11Wrong answer0/2178ms9948 KiB
12Wrong answer0/2160ms9352 KiB
13Wrong answer0/2172ms9248 KiB
14Accepted2/252ms10036 KiB
15Accepted3/354ms10064 KiB
16Accepted3/397ms10036 KiB
17Accepted2/296ms10120 KiB
18Accepted3/397ms10152 KiB
19Accepted2/2160ms9016 KiB
20Wrong answer0/2171ms9540 KiB
21Wrong answer0/2175ms10044 KiB
22Wrong answer0/2177ms10072 KiB
23Wrong answer0/2178ms10208 KiB
24Wrong answer0/2177ms10036 KiB
25Accepted2/2185ms10076 KiB