107782024-04-12 12:23:42MagyarKendeSZLGFestés (50 pont)cpp17Wrong answer 10/50689ms63668 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define vec vector
#define sz(v) (int)v.size()

int N, M;
vec<ll> rowS;
vec<vec<vec<ll>>> colS;
ll res = LLONG_MAX;

void solve(vector<bool> painted) {
    if (sz(painted) == N) {
        ll curr = 0;
        for (int i = 0; i < N; i++) {
            if (painted[i]) curr += rowS[i];
        }

        for (int i = 0; i < M; i++) {
            ll mn = LLONG_MAX;
            for (int j = 0; j < N; j++) {
                for (int k = j; k < N; k++) {
                    vector<bool> mask = painted;
                    for (int l = j; l <= k; l++) {
                        mask[l] = 1;
                    }
                    if (count(mask.begin(), mask.end(), 1) == N) {
                        mn = min(mn, colS[i][j][k]);
                    }
                }
            }
            curr += mn;
        }
        res = min(res, curr);
    } else {
        painted.push_back(0);
        solve(painted);
        painted.back() = 1;
        solve(painted);
        painted.pop_back();
    }
}

int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> N >> M;
    rowS.resize(N);
    colS.assign(M, vec<vec<ll>>(N, vec<ll>(N)));

    for (int i = 0; i < N; i++) {
        cin >> rowS[i];
    }
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = j; k < N; k++) {
                cin >> colS[i][j][k];
            }
        }
    }

    solve({});
    cout << res;
}
SubtaskSumTestVerdictTimeMemory
base10/50
1Accepted0/03ms1832 KiB
2Wrong answer0/03ms2028 KiB
3Wrong answer0/2363ms41124 KiB
4Wrong answer0/24ms2232 KiB
5Wrong answer0/314ms3040 KiB
6Wrong answer0/2115ms8720 KiB
7Time limit exceeded0/2666ms34276 KiB
8Time limit exceeded0/2657ms34364 KiB
9Time limit exceeded0/2675ms34620 KiB
10Time limit exceeded0/2684ms36820 KiB
11Time limit exceeded0/2661ms41672 KiB
12Time limit exceeded0/2689ms43708 KiB
13Time limit exceeded0/2663ms48700 KiB
14Accepted2/2119ms51200 KiB
15Accepted3/3119ms52816 KiB
16Accepted3/3361ms63668 KiB
17Accepted2/2358ms63664 KiB
18Wrong answer0/3360ms63660 KiB
19Time limit exceeded0/2670ms52776 KiB
20Time limit exceeded0/2675ms54428 KiB
21Time limit exceeded0/2675ms55752 KiB
22Time limit exceeded0/2684ms56184 KiB
23Time limit exceeded0/2667ms56136 KiB
24Time limit exceeded0/2675ms56328 KiB
25Time limit exceeded0/2671ms56292 KiB