提出 #65455545


ソースコード 拡げる

#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long
#define PII pair<int,int>
#define mod 998244353
const int MOD=1e9+7;
const int N=1e5+10;
int read() {char act = 0;int f = 1, x= 0;while (act = getchar(), act < '0' && act != '-');if (act == '-') f = -1, act = getchar();x = act - '0';while (act = getchar(), act >= '0') x = x * 10 + act - '0';return x * f;}
void solve(){
    int N, M;
    cin >> N >> M;
    vector<long long> C(N + 10);
    for (int i = 1; i <= N; i++) {
        cin >> C[i];
    }
    vector<vector<int>> zoo(M);
    for (int i = 0; i < M; i++) {
        int K;
        cin >> K;
        vector<int> list(K);
        for (int j = 0; j < K; j++) {
            cin >> list[j];
        }
        zoo[i] = list;
    }

    long long ans = LLONG_MAX;
    int maxx = 1;
    for (int i = 0; i < N; i++) {
        maxx *= 3;
    }

    for (int mask = 0; mask < maxx; mask++) {
        int x[N + 1] = {0}; // x[1..N]
        long long cost = 0;
        int tmp = mask;
        for (int j = 0; j < N; j++) {
            int cnt = tmp % 3;
            tmp /= 3;
            x[j + 1] = cnt;
            cost += cnt * C[j + 1];
        }

        bool flag = true;
        for (int i = 0; i < M; i++) {
            int sum = 0;
            for (int a : zoo[i]) {
                sum += x[a];
                if (sum >= 2) break;
            }
            if (sum < 2) {
                flag = false;
                break;
            }
        }

        if (flag && cost < ans) {
            ans = cost;
        }
    }

    cout << ans << endl;
}
signed main()
{
    IOS;
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}

提出情報

提出日時
問題 D - Goin' to the Zoo
ユーザ Freakkk
言語 C++ 20 (gcc 12.2)
得点 400
コード長 1883 Byte
結果 AC
実行時間 41 ms
メモリ 3636 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 2
AC × 35
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
hand_01.txt AC 1 ms 3400 KiB
hand_02.txt AC 1 ms 3440 KiB
hand_03.txt AC 1 ms 3400 KiB
random_01.txt AC 41 ms 3444 KiB
random_02.txt AC 40 ms 3520 KiB
random_03.txt AC 9 ms 3440 KiB
random_04.txt AC 16 ms 3432 KiB
random_05.txt AC 4 ms 3436 KiB
random_06.txt AC 1 ms 3432 KiB
random_07.txt AC 18 ms 3440 KiB
random_08.txt AC 1 ms 3440 KiB
random_09.txt AC 2 ms 3448 KiB
random_10.txt AC 1 ms 3432 KiB
random_11.txt AC 12 ms 3572 KiB
random_12.txt AC 1 ms 3576 KiB
random_13.txt AC 3 ms 3372 KiB
random_14.txt AC 1 ms 3628 KiB
random_15.txt AC 10 ms 3436 KiB
random_16.txt AC 1 ms 3516 KiB
random_17.txt AC 4 ms 3572 KiB
random_18.txt AC 1 ms 3636 KiB
random_19.txt AC 2 ms 3428 KiB
random_20.txt AC 3 ms 3504 KiB
random_21.txt AC 1 ms 3512 KiB
random_22.txt AC 2 ms 3504 KiB
random_23.txt AC 1 ms 3508 KiB
random_24.txt AC 1 ms 3432 KiB
random_25.txt AC 1 ms 3508 KiB
random_26.txt AC 3 ms 3496 KiB
random_27.txt AC 1 ms 3500 KiB
random_28.txt AC 1 ms 3436 KiB
random_29.txt AC 1 ms 3500 KiB
random_30.txt AC 1 ms 3368 KiB
sample_01.txt AC 1 ms 3424 KiB
sample_02.txt AC 1 ms 3488 KiB