Submission #65472990


Source Code Expand

#include <bits/stdc++.h>
#define REP(i, n)     for(int i = 0; i < (int)(n); ++i)
#define RREP(i, n)    for(int i = (int)(n); i-- > 0;)
#define FOR(i, l, r)  for(int i = (int)(l); i < (int)(r); ++i)
#define RFOR(i, r, l) for(int i = (int)(r); i-- > (int)(l);)
#define ALL(v)        std::begin(v), std::end(v)
using llong = long long;
using vi    = std::vector<int>;
using vvi   = std::vector<vi>;
using pii   = std::pair<int, int>;
using namespace std;
constexpr int       INF  = 1e9;
constexpr long long LINF = 1e18;
constexpr double    EPS  = 1e-10;
constexpr int       MOD  = 998'244'353;
constexpr int       MOD2 = 1e9 + 7;

template <typename Type>
inline std::istream &operator>>(std::istream &is, std::vector<Type> &v) {
    for(auto &elem : v) is >> elem;
    return is;
}

template <typename Type>
inline std::ostream &operator<<(std::ostream &os, const std::vector<Type> &v) {
    for(auto iter = v.cbegin(); iter != v.cend(); ++iter) os << (iter == v.cbegin() ? "" : " ") << *iter;
    return os;
}

#ifdef DEBUG

#include "debug.hpp"

#else

#define debug(...) static_cast<void>(0)

#endif

template <typename Type>
std::vector<Type> table(std::size_t n, const Type &val) { return std::vector<Type>(n, val); }

template <typename... Args>
auto table(std::size_t n, const Args &...args) { return std::vector(n, table(args...)); }

constexpr int popcount32(uint32_t bit) {
    bit -= (bit >> 1) & 0x55555555U;
    bit = (bit & 0x33333333U) + ((bit >> 2) & 0x33333333U);
    bit = (bit + (bit >> 4)) & 0x0f0f0f0fU;
    bit += bit >> 8;
    bit += bit >> 16;
    return bit & 0x3fU;
}

constexpr int popcount64(uint64_t bit) {
    bit -= (bit >> 1) & 0x5555555555555555ULL;
    bit = (bit & 0x3333333333333333ULL) + ((bit >> 2) & 0x3333333333333333ULL);
    bit = (bit + (bit >> 4)) & 0x0f0f0f0f0f0f0f0fULL;
    bit += bit >> 8;
    bit += bit >> 16;
    bit += bit >> 32;
    return bit & 0x7fULL;
}

int main(){
    int n;
    int m;
    cin>>n>>m;

    vector<llong> c(n);
    cin>>c;

    vector<int> a(m,0);
    REP(i,m){
        int k;
        cin>>k;

        REP(j,k){
            int b;
            cin>>b;
            b--;
            a[i]|=1<<b;
        }
    }
    debug(a);

    llong ans=LINF;
    auto calc=[&](int bit)->llong{
        llong res=0;
        REP(i,n){
            if(bit>>i&1) res+=c[i];
            if(bit>>(n+i)&1) res+=c[i];
        }
        return res;
    };
    REP(bit,1<<(2*n)){
        bool ng=false;
        REP(i,m){
            int bit2=(bit&a[i])|(bit&a[i]<<n);
            if(popcount32(bit2)<2){
                ng=true;
                break;
            }
        }
        if(ng) continue; 
        debug(bitset<20>(bit));
   
        auto tmp=calc(bit);
        ans=min(ans,tmp);
    }
    
    cout<<ans<<endl;
}

Submission Info

Submission Time
Task D - Goin' to the Zoo
User Today
Language C++ 23 (gcc 12.2)
Score 400
Code Size 2884 Byte
Status AC
Exec Time 269 ms
Memory 3700 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 35
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All hand_01.txt, hand_02.txt, hand_03.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
hand_01.txt AC 2 ms 3492 KiB
hand_02.txt AC 1 ms 3512 KiB
hand_03.txt AC 1 ms 3552 KiB
random_01.txt AC 269 ms 3516 KiB
random_02.txt AC 268 ms 3572 KiB
random_03.txt AC 89 ms 3496 KiB
random_04.txt AC 188 ms 3484 KiB
random_05.txt AC 58 ms 3652 KiB
random_06.txt AC 14 ms 3392 KiB
random_07.txt AC 220 ms 3672 KiB
random_08.txt AC 2 ms 3568 KiB
random_09.txt AC 57 ms 3568 KiB
random_10.txt AC 1 ms 3560 KiB
random_11.txt AC 183 ms 3508 KiB
random_12.txt AC 1 ms 3560 KiB
random_13.txt AC 62 ms 3700 KiB
random_14.txt AC 1 ms 3508 KiB
random_15.txt AC 156 ms 3560 KiB
random_16.txt AC 1 ms 3496 KiB
random_17.txt AC 68 ms 3504 KiB
random_18.txt AC 1 ms 3556 KiB
random_19.txt AC 4 ms 3564 KiB
random_20.txt AC 72 ms 3556 KiB
random_21.txt AC 1 ms 3560 KiB
random_22.txt AC 9 ms 3488 KiB
random_23.txt AC 1 ms 3692 KiB
random_24.txt AC 3 ms 3700 KiB
random_25.txt AC 1 ms 3504 KiB
random_26.txt AC 18 ms 3656 KiB
random_27.txt AC 1 ms 3492 KiB
random_28.txt AC 1 ms 3648 KiB
random_29.txt AC 2 ms 3564 KiB
random_30.txt AC 3 ms 3500 KiB
sample_01.txt AC 1 ms 3568 KiB
sample_02.txt AC 2 ms 3628 KiB