結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
11,392 KB
testcase_01 AC 77 ms
11,516 KB
testcase_02 AC 58 ms
11,392 KB
testcase_03 AC 84 ms
11,372 KB
testcase_04 AC 87 ms
11,384 KB
testcase_05 AC 86 ms
11,464 KB
testcase_06 AC 87 ms
11,372 KB
testcase_07 AC 85 ms
11,392 KB
testcase_08 AC 84 ms
11,392 KB
testcase_09 AC 83 ms
11,388 KB
testcase_10 AC 88 ms
11,392 KB
testcase_11 AC 87 ms
11,392 KB
testcase_12 AC 81 ms
11,440 KB
testcase_13 AC 83 ms
11,396 KB
testcase_14 AC 85 ms
11,392 KB
testcase_15 AC 84 ms
11,448 KB
testcase_16 AC 82 ms
11,484 KB
testcase_17 AC 86 ms
11,464 KB
testcase_18 AC 86 ms
11,524 KB
testcase_19 AC 85 ms
11,372 KB
testcase_20 AC 84 ms
11,392 KB
testcase_21 AC 85 ms
11,404 KB
testcase_22 AC 85 ms
11,476 KB
testcase_23 AC 83 ms
11,368 KB
testcase_24 AC 87 ms
11,392 KB
testcase_25 AC 85 ms
11,392 KB
testcase_26 AC 83 ms
11,412 KB
testcase_27 AC 86 ms
11,500 KB
testcase_28 AC 61 ms
11,392 KB
testcase_29 AC 66 ms
11,392 KB
testcase_30 AC 69 ms
11,444 KB
testcase_31 AC 73 ms
11,496 KB
testcase_32 AC 77 ms
11,372 KB
testcase_33 AC 80 ms
11,392 KB
testcase_34 AC 82 ms
11,392 KB
testcase_35 AC 82 ms
11,348 KB
testcase_36 AC 83 ms
11,452 KB
testcase_37 AC 84 ms
11,520 KB
testcase_38 AC 86 ms
11,400 KB
testcase_39 AC 88 ms
11,520 KB
testcase_40 AC 90 ms
11,392 KB
testcase_41 AC 89 ms
11,392 KB
testcase_42 AC 88 ms
11,388 KB
testcase_43 AC 85 ms
11,392 KB
testcase_44 AC 82 ms
11,392 KB
testcase_45 AC 68 ms
11,392 KB
testcase_46 AC 77 ms
11,548 KB
testcase_47 AC 58 ms
11,416 KB
testcase_48 AC 86 ms
11,404 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];
            assert(a[j] >= 1);
            assert(a[j] <= 19);
            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