197042025-12-19 10:34:10ubormaciFestés (50 pont)cpp17Időlimit túllépés 7/50700ms7668 KiB
#include <iostream>
#include <algorithm> // for sort, mainly
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <array>
#include <string>
#include <cstdio>
#include <iterator>
#include <unordered_set>
#include <cstdint> // for int64_t, int32_t, etc
#include <queue>
#include <stack>
#include <deque>
#include <numeric> // gcd, lcm
#include <fstream>
#include <bitset> // for bitset
#include <iomanip>
#include <cassert> // for set with custom ordering
#include <type_traits> // for set with custom ordering
#include <utility> // for swap, forward, etc
using namespace std;

#pragma GCC optimize("O2")
// #pragma GCC optimize("O1","O2","O3","Ofast","unroll-loops")
//#pragma GCC target("sse","sse2","sse3","sse4.1","sse4.2","avx","avx2","fma")

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#ifdef LOCAL
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

/*
 *
 * notes:
 *
 * int64_t
 * stoi(string s) -> string to int
 * to_string() -> int (or else) to string
 *
 * vector declaration:
 * vector<ll> v(n, 0)
 * vector<vector<ll>> v(n, vector<ll>(n, 0));
 *
 * {if statement} ? {truth value} : {false value}
 *
 * set lower bound/upper bound:
 * 	// . . . m1 . . . d . . . . m2
 *    auto m1_it = b.lower_bound(d);
 *    advance(m1_it, -1);
 *    m1 = *m1_it;
 *	m2 = *b.upper_bound(d);
 *
 * #ifdef LOCAL
 *    freopen("in.txt","r",stdin);
 *    freopen("out.txt","w",stdout);
 * #endif
 *
 * constexpr auto lcm(auto x, auto... xs)
 * {
 *	return ((x = std::lcm(x, xs)), ...);
 * }
 *
 * std::gcd(int a, int b)
 *
 * cout << setprecision(n);
 *
 * set with custom ordering
 * set<ll, decltype(&cmp)> qu(cmp);
 *
 */

typedef int32_t ll;

void solve() {

    ll n, m;
    cin >> n >> m;

    vector<ll> tp(11, 1);
    for(ll i = 1; i <= 10; i++) {
        tp[i] = 2 * tp[i-1];
    }

    ll finans = 0;

    vector<ll> row(n, 0);
    for(ll i = 0; i < n; i++) {
        cin >> row[i];
        finans += row[i];
    }

    ll gn = (n * (n+1))/2;

    vector<vector<ll>> col(m, vector<ll>(gn, 0));

    vector<pair<ll,ll>> seg(gn, {0,0});

    for(ll i = 0; i < m; i++) {

        ll j = 0;

        for(ll f = 0; f < n; f++) {
            for(ll s = f; s < n; s++) {

                cin >> col[i][j];

                seg[j] = {f,s};

                j++;

            }   
        }
    }

    for(ll i = 0; i < tp[n]; i++) {

        // melyik row-ok vannak elore kitoltve

        ll ansh = 0;

        bitset<11> rf(false);
        ll c = i;
        ll ci = 0;
        while(c > 0) {
            rf[ci] = (c % 2 == 1);
            
            if(rf[ci]) {
                ansh += row[ci];
            }
            
            c /= 2;
            ci++;
        }
        
        //cerr << "\nrf=" << rf;

        for(ll j = 0; j < m; j++) {

            //cerr << "\nj=" << j;

            ll h = INT32_MAX;

            for(ll c = 0; c < tp[gn]; c++) {

                ll hh = 0;

                bitset<11> cf = rf;
                ll ci = 0;
                ll cc = c;
                while(cc > 0) {
                    if(cc % 2 == 1) {
                        hh += col[j][ci];

                        // how to set the columns to true
                        // hmmmmmmm
                        for(ll fill = seg[ci].first; fill <= seg[ci].second; fill++) {
                            cf[fill] = true;
                        }
                    }

                    cc /= 2;
                    ci++;
                }

                //cerr << "\nc=" << c;
                //cerr << "\ncf=" << cf;

                bool all = true;
                for(ll check = 0; check < n; check++) {
                    if(cf[check] == false) {
                        all = false;
                        break;
                    }
                }

                if(all == true) {
                    h = min(h, hh);
                }

            }

            ansh += h;

        }

        finans = min(finans, ansh);
    }

    cout << finans;

}

int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    solve();

    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base7/50
1Elfogadva0/01ms316 KiB
2Elfogadva0/014ms316 KiB
3Időlimit túllépés0/2676ms5684 KiB
4Elfogadva2/2127ms316 KiB
5Időlimit túllépés0/3699ms316 KiB
6Időlimit túllépés0/2699ms1076 KiB
7Időlimit túllépés0/2680ms7476 KiB
8Időlimit túllépés0/2683ms7476 KiB
9Időlimit túllépés0/2699ms7424 KiB
10Időlimit túllépés0/2700ms7220 KiB
11Időlimit túllépés0/2677ms7220 KiB
12Időlimit túllépés0/2681ms6828 KiB
13Időlimit túllépés0/2685ms6708 KiB
14Elfogadva2/275ms5684 KiB
15Elfogadva3/376ms5684 KiB
16Időlimit túllépés0/3699ms5684 KiB
17Időlimit túllépés0/2680ms5684 KiB
18Időlimit túllépés0/3680ms5684 KiB
19Időlimit túllépés0/2680ms6740 KiB
20Időlimit túllépés0/2680ms6964 KiB
21Időlimit túllépés0/2676ms7220 KiB
22Időlimit túllépés0/2686ms7476 KiB
23Időlimit túllépés0/2700ms7220 KiB
24Időlimit túllépés0/2685ms7220 KiB
25Időlimit túllépés0/2685ms7668 KiB