Submission #65433479


Source Code Expand

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
#define pb push_back
#define ff first
#define ss second
const int N=2e3+7;
const int mod=1e9+7;
const double eps=1e-9;
const double pi=    3.14159265358979323846;
using namespace std;  
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    op_set;

string rep(int n,int len)
{
    string a="";
    for(int i=0;i<len;i++,n=n/3)
        a+=(char)('0'+n%3);
    reverse(a.begin(),a.end());
    return a;
}

int32_t main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n,m;
    cin >> n >> m;

    vector<long long> costs(n);
    for(int i=0;i<n;i++)
        cin >> costs[i];

    vector<vector<int>> zoo(n);
    for(int i=0;i<m;i++)
    {
        int k;
        cin >> k;
        while(k--)
        {
            int ex;
            cin >> ex;
            zoo[ex-1].pb(i);
        }
    }

    long long ans=1e18;
    int highest=pow(3,n);
    for(int i=1;i<highest;i++)
    {
        string tmp=rep(i,n);
        long long curr=0ll;
        for(int j=0;j<n;j++)
            curr+=(tmp[j]-'0')*costs[j];

        vector<int> animals(m);
        for(int j=0;j<n;j++)
            for(auto animal : zoo[j])
                animals[animal]+=(tmp[j]-'0');

        if(*std::min_element(animals.begin(),animals.end())>=2)
            ans=std::min(ans,curr);
    }
    cout << ans << "\n";
}

/*
Mar Gaye Ehsaas Meray, 
Chubay Wo Ilfaaz Teray, 
Tumne Dekha Tak Na Jaty Way, 
*/

Submission Info

Submission Time
Task D - Goin' to the Zoo
User 18o3
Language C++ 20 (gcc 12.2)
Score 400
Code Size 1673 Byte
Status AC
Exec Time 42 ms
Memory 3816 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 1 ms 3752 KiB
hand_02.txt AC 1 ms 3752 KiB
hand_03.txt AC 1 ms 3616 KiB
random_01.txt AC 42 ms 3688 KiB
random_02.txt AC 42 ms 3700 KiB
random_03.txt AC 22 ms 3740 KiB
random_04.txt AC 26 ms 3672 KiB
random_05.txt AC 6 ms 3756 KiB
random_06.txt AC 2 ms 3756 KiB
random_07.txt AC 27 ms 3664 KiB
random_08.txt AC 1 ms 3620 KiB
random_09.txt AC 6 ms 3644 KiB
random_10.txt AC 1 ms 3700 KiB
random_11.txt AC 27 ms 3624 KiB
random_12.txt AC 1 ms 3668 KiB
random_13.txt AC 5 ms 3760 KiB
random_14.txt AC 1 ms 3696 KiB
random_15.txt AC 25 ms 3576 KiB
random_16.txt AC 1 ms 3768 KiB
random_17.txt AC 6 ms 3816 KiB
random_18.txt AC 1 ms 3752 KiB
random_19.txt AC 5 ms 3756 KiB
random_20.txt AC 8 ms 3696 KiB
random_21.txt AC 1 ms 3756 KiB
random_22.txt AC 5 ms 3632 KiB
random_23.txt AC 1 ms 3612 KiB
random_24.txt AC 2 ms 3696 KiB
random_25.txt AC 1 ms 3752 KiB
random_26.txt AC 5 ms 3696 KiB
random_27.txt AC 1 ms 3656 KiB
random_28.txt AC 1 ms 3608 KiB
random_29.txt AC 2 ms 3752 KiB
random_30.txt AC 2 ms 3596 KiB
sample_01.txt AC 1 ms 3700 KiB
sample_02.txt AC 1 ms 3736 KiB