結果

問題 No.2152 [Cherry Anniversary 2] 19 Petals of Cherry
ユーザー t98slider
提出日時 2022-12-09 00:36:23
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 152 ms / 1,000 ms
コード長 849 bytes
コンパイル時間 1,541 ms
コンパイル使用メモリ 172,052 KB
実行使用メモリ 31,872 KB
最終ジャッジ日時 2024-10-14 18:20:45
合計ジャッジ時間 7,280 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<int> S(19);
    for(int i = 0; i < 19; i++){
        int L, v;
        cin >> L;
        while(L--){
            cin >> v;
            S[i] |= 1 << v - 1;
        }
    }
    vector<vector<ll>> dp(1 << 19, vector<ll>(2));
    dp[0][0] = 1;
    for(int i = 0; i < (1 << 19); i++){
        for(int j = 0; j < 2; j++){
            if(dp[i][j] == 0)continue;
            int p = __builtin_popcount(i), cnt = 0;
            for(int k = 0; k < 19; k++){
                if(i >> k & 1)continue;
                cnt++;
                if(~S[k] >> p & 1)continue;
                dp[i | (1 << k)][j ^ (cnt & 1) ^ 1] += dp[i][j];
            }
        }
    }
    cout << dp.back()[0] << ' ' << dp.back()[1] << '\n';
}
0