84042024-01-15 15:52:44kukkermanFestés (50 pont)cpp17Accepted 50/50517ms67616 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>

using SorKoltsegek = std::vector<uint64_t>;
using OszlopKoltsegek = std::vector<std::vector<std::vector<uint64_t>>>;

void beolvas(std::istream &be, SorKoltsegek &r, OszlopKoltsegek &o) {
    int n, m;
    be >> n >> m;

    r.resize(n);
    for (auto &akt_sor : r) {
        be >> akt_sor;
    }

    o.resize(m);
    for (auto &akt_oszlop : o) {
        akt_oszlop.resize(n);
        for (int l = 0; l < n; l++) {
            akt_oszlop[l].resize(n);
            for (int r = l; r < n; r++) {
                be >> akt_oszlop[l][r];
            }
        }
    }
}

uint64_t min_oszlop_koltseg(int sorok, int oszlop, int kifestett_sorok, const OszlopKoltsegek &c) {
    std::vector<uint64_t> dp(sorok + 1, std::numeric_limits<uint64_t>::max());

    dp[0] = 0;
    for (auto akt_sor = 0; akt_sor < sorok; akt_sor++) {
        auto min_legalabb_elso_sorig = std::numeric_limits<uint64_t>::max();
        for (auto elso_kifestendo_sor = akt_sor; elso_kifestendo_sor >= 0; elso_kifestendo_sor--) {
            min_legalabb_elso_sorig = std::min(min_legalabb_elso_sorig, dp[elso_kifestendo_sor]);
            dp[akt_sor + 1] = std::min(dp[akt_sor + 1], min_legalabb_elso_sorig + c[oszlop][elso_kifestendo_sor][akt_sor]);
        }

        if ((kifestett_sorok & (1 << akt_sor)) > 0) {
            dp[akt_sor + 1] = std::min(dp[akt_sor + 1], dp[akt_sor]);
        }
    }

    return dp[sorok];
}

void feldolgoz(const SorKoltsegek &r, const OszlopKoltsegek &c) {
    const auto sorok = r.size();
    const auto oszlopok = c.size();
    const int max_sor_halmaz = (1 << sorok);

    auto min_koltseg = std::numeric_limits<uint64_t>::max();
    for (int kifestett_sorok = 0; kifestett_sorok < max_sor_halmaz; kifestett_sorok++) {
        uint64_t akt_koltseg = 0u;
        for (int sor = 0; sor < sorok; sor++) {
            if ((kifestett_sorok & (1 << sor)) > 0) {
                akt_koltseg += r[sor];
            }
        }

        for (int oszlop = 0; oszlop < oszlopok; oszlop++) {
            akt_koltseg += min_oszlop_koltseg(static_cast<int>(sorok), oszlop, kifestett_sorok, c);
        }
        min_koltseg = std::min(min_koltseg, akt_koltseg);
    }

    std::cout << min_koltseg << '\n';
}

int main() {
    SorKoltsegek r;
    OszlopKoltsegek c;
    beolvas(std::cin, r, c);

    feldolgoz(r, c);

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1812 KiB
2Accepted0/03ms2064 KiB
3Accepted2/2293ms41128 KiB
4Accepted2/23ms2592 KiB
5Accepted3/36ms3084 KiB
6Accepted2/245ms8680 KiB
7Accepted2/2479ms66640 KiB
8Accepted2/2476ms66512 KiB
9Accepted2/2474ms66864 KiB
10Accepted2/2481ms66876 KiB
11Accepted2/2465ms66608 KiB
12Accepted2/2423ms61584 KiB
13Accepted2/2455ms61764 KiB
14Accepted2/2150ms32792 KiB
15Accepted3/3151ms32752 KiB
16Accepted3/3268ms42260 KiB
17Accepted2/2268ms42420 KiB
18Accepted3/3263ms42496 KiB
19Accepted2/2414ms60948 KiB
20Accepted2/2446ms64084 KiB
21Accepted2/2467ms66680 KiB
22Accepted2/2472ms67464 KiB
23Accepted2/2479ms67468 KiB
24Accepted2/2462ms67616 KiB
25Accepted2/2517ms67464 KiB