結果

問題 No.2152 [Cherry Anniversary 2] 19 Petals of Cherry
ユーザー AngrySadEightAngrySadEight
提出日時 2022-12-05 13:18:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 83 ms / 1,000 ms
コード長 1,468 bytes
コンパイル時間 911 ms
コンパイル使用メモリ 76,772 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-04-22 18:36:05
合計ジャッジ時間 5,683 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
11,392 KB
testcase_01 AC 69 ms
11,392 KB
testcase_02 AC 53 ms
11,392 KB
testcase_03 AC 79 ms
11,392 KB
testcase_04 AC 80 ms
11,392 KB
testcase_05 AC 79 ms
11,392 KB
testcase_06 AC 82 ms
11,392 KB
testcase_07 AC 79 ms
11,520 KB
testcase_08 AC 77 ms
11,392 KB
testcase_09 AC 75 ms
11,392 KB
testcase_10 AC 80 ms
11,264 KB
testcase_11 AC 79 ms
11,392 KB
testcase_12 AC 74 ms
11,392 KB
testcase_13 AC 78 ms
11,392 KB
testcase_14 AC 82 ms
11,392 KB
testcase_15 AC 83 ms
11,392 KB
testcase_16 AC 76 ms
11,520 KB
testcase_17 AC 81 ms
11,392 KB
testcase_18 AC 79 ms
11,520 KB
testcase_19 AC 78 ms
11,392 KB
testcase_20 AC 76 ms
11,392 KB
testcase_21 AC 75 ms
11,392 KB
testcase_22 AC 78 ms
11,392 KB
testcase_23 AC 76 ms
11,392 KB
testcase_24 AC 80 ms
11,520 KB
testcase_25 AC 81 ms
11,392 KB
testcase_26 AC 78 ms
11,392 KB
testcase_27 AC 79 ms
11,392 KB
testcase_28 AC 59 ms
11,520 KB
testcase_29 AC 60 ms
11,392 KB
testcase_30 AC 63 ms
11,520 KB
testcase_31 AC 68 ms
11,520 KB
testcase_32 AC 71 ms
11,392 KB
testcase_33 AC 74 ms
11,392 KB
testcase_34 AC 75 ms
11,520 KB
testcase_35 AC 75 ms
11,392 KB
testcase_36 AC 75 ms
11,392 KB
testcase_37 AC 78 ms
11,520 KB
testcase_38 AC 79 ms
11,392 KB
testcase_39 AC 80 ms
11,392 KB
testcase_40 AC 82 ms
11,392 KB
testcase_41 AC 82 ms
11,392 KB
testcase_42 AC 81 ms
11,520 KB
testcase_43 AC 76 ms
11,392 KB
testcase_44 AC 75 ms
11,520 KB
testcase_45 AC 64 ms
11,392 KB
testcase_46 AC 71 ms
11,392 KB
testcase_47 AC 55 ms
11,392 KB
testcase_48 AC 81 ms
11,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
typedef long long ll;

int main(){
    vector<ll> L(19);
    vector<ll> A(19, 0);
    for (ll i = 0; i < 19; i++){
        cin >> L[i];
        assert(L[i] >= 0 && L[i] <= 19);
        vector<ll> a(L[i]);
        for (ll j = 0; j < L[i]; j++){
            cin >> a[j];
            if (j >= 1){
                assert(a[j] > a[j - 1]);
            }
            A[i] += (1LL << (a[j] - 1));
        }
    }
    /*for (ll i = 0; i < 19; i++){
        cout << A[i] << " ";
    }
    cout << endl;*/

    vector<ll> dp1((1 << 19), 0);//奇数
    vector<ll> dp2((1 << 19), 0);//偶数
    dp2[0] = 1;
    for (ll i = 0; i < (1 << 19) - 1; i++){
        ll popcnt1 = __builtin_popcount(i);
        for (ll j = 0; j < 19; j++){
            if ((i >> j) & 1){
                continue;
            }
            if ((A[j] >> popcnt1) & 1){
                ll bitmask = (1 << (j + 1)) - 1;
                bitmask = bitmask ^ ((1 << 19) - 1);
                ll popcnt2 = __builtin_popcount(bitmask & i);
                if (popcnt2 % 2 == 1){
                    dp1[i | (1 << j)] += dp2[i];
                    dp2[i | (1 << j)] += dp1[i];
                }
                else{
                    dp1[i | (1 << j)] += dp1[i];
                    dp2[i | (1 << j)] += dp2[i];
                }
            }
        }
    }
    cout << dp2[(1 << 19) - 1] << " " << dp1[(1 << 19) - 1] << endl;
}
0