結果

問題 No.2152 [Cherry Anniversary 2] 19 Petals of Cherry
ユーザー 👑 KazunKazun
提出日時 2022-11-28 02:32:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 1,000 ms
コード長 1,068 bytes
コンパイル時間 2,635 ms
コンパイル使用メモリ 201,796 KB
実行使用メモリ 13,568 KB
最終ジャッジ日時 2024-04-22 18:35:47
合計ジャッジ時間 7,193 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
13,440 KB
testcase_01 AC 66 ms
13,440 KB
testcase_02 AC 52 ms
13,440 KB
testcase_03 AC 63 ms
13,568 KB
testcase_04 AC 67 ms
13,440 KB
testcase_05 AC 65 ms
13,440 KB
testcase_06 AC 64 ms
13,440 KB
testcase_07 AC 65 ms
13,440 KB
testcase_08 AC 63 ms
13,568 KB
testcase_09 AC 66 ms
13,440 KB
testcase_10 AC 68 ms
13,440 KB
testcase_11 AC 64 ms
13,568 KB
testcase_12 AC 65 ms
13,568 KB
testcase_13 AC 64 ms
13,440 KB
testcase_14 AC 65 ms
13,440 KB
testcase_15 AC 65 ms
13,440 KB
testcase_16 AC 65 ms
13,568 KB
testcase_17 AC 66 ms
13,440 KB
testcase_18 AC 63 ms
13,568 KB
testcase_19 AC 66 ms
13,440 KB
testcase_20 AC 63 ms
13,440 KB
testcase_21 AC 68 ms
13,440 KB
testcase_22 AC 66 ms
13,440 KB
testcase_23 AC 68 ms
13,440 KB
testcase_24 AC 65 ms
13,568 KB
testcase_25 AC 65 ms
13,440 KB
testcase_26 AC 64 ms
13,568 KB
testcase_27 AC 63 ms
13,440 KB
testcase_28 AC 54 ms
13,440 KB
testcase_29 AC 59 ms
13,568 KB
testcase_30 AC 63 ms
13,440 KB
testcase_31 AC 65 ms
13,440 KB
testcase_32 AC 67 ms
13,568 KB
testcase_33 AC 68 ms
13,440 KB
testcase_34 AC 68 ms
13,440 KB
testcase_35 AC 70 ms
13,568 KB
testcase_36 AC 71 ms
13,440 KB
testcase_37 AC 71 ms
13,568 KB
testcase_38 AC 73 ms
13,440 KB
testcase_39 AC 73 ms
13,440 KB
testcase_40 AC 71 ms
13,568 KB
testcase_41 AC 70 ms
13,568 KB
testcase_42 AC 67 ms
13,440 KB
testcase_43 AC 65 ms
13,440 KB
testcase_44 AC 60 ms
13,440 KB
testcase_45 AC 52 ms
13,440 KB
testcase_46 AC 56 ms
13,312 KB
testcase_47 AC 52 ms
13,440 KB
testcase_48 AC 70 ms
13,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
using ll=long long;

bool bit(int S, int k){
    return (S>>k)&1;
}

int main(){
    const int N=19;
    const int U=1<<N;

    vector<vector<bool>> B(N, vector<bool>(N, false));

    for (int i=0; i<N; i++){
        int L; cin >> L;
        for (int j=0; j<L; j++){
            int a; cin >> a;
            B[i][a-1]=true;
        }
    }

    vector<int> popcount(U, 0);
    for (int S=1; S<(1<<N); S++){
        popcount[S]=popcount[S>>1]+(S&1);
    }

    vector<ll> DP0(U, 0), DP1(U, 0);
    for (int S=U-1; S>=0; S--){
        if (popcount[S]==N){
            DP0[S]=1;
            continue;
        }

        int t=0;
        for (int j=0; j<N; j++){
            if (bit(S,j)) continue;

            if (B[popcount[S]][j]){
                int T=S|(1<<j);
                if (t&1){
                    DP0[S]+=DP1[T]; DP1[S]+=DP0[T];
                }else{
                    DP0[S]+=DP0[T]; DP1[S]+=DP1[T];
                }
            }
            t++;
        }
    }
    cout << DP0[0] << " "  << DP1[0];
}
0