結果

問題 No.2152 [Cherry Anniversary 2] 19 Petals of Cherry
ユーザー 👑 NachiaNachia
提出日時 2024-04-22 22:47:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 1,000 ms
コード長 2,072 bytes
コンパイル時間 973 ms
コンパイル使用メモリ 81,528 KB
実行使用メモリ 11,464 KB
最終ジャッジ日時 2024-04-22 22:47:54
合計ジャッジ時間 5,439 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
11,448 KB
testcase_01 AC 57 ms
11,284 KB
testcase_02 AC 50 ms
11,376 KB
testcase_03 AC 65 ms
11,428 KB
testcase_04 AC 64 ms
11,400 KB
testcase_05 AC 68 ms
11,416 KB
testcase_06 AC 63 ms
11,352 KB
testcase_07 AC 68 ms
11,380 KB
testcase_08 AC 65 ms
11,464 KB
testcase_09 AC 62 ms
11,324 KB
testcase_10 AC 65 ms
11,348 KB
testcase_11 AC 63 ms
11,328 KB
testcase_12 AC 66 ms
11,280 KB
testcase_13 AC 63 ms
11,392 KB
testcase_14 AC 68 ms
11,264 KB
testcase_15 AC 69 ms
11,264 KB
testcase_16 AC 63 ms
11,280 KB
testcase_17 AC 65 ms
11,392 KB
testcase_18 AC 78 ms
11,392 KB
testcase_19 AC 70 ms
11,264 KB
testcase_20 AC 61 ms
11,388 KB
testcase_21 AC 63 ms
11,348 KB
testcase_22 AC 70 ms
11,392 KB
testcase_23 AC 64 ms
11,392 KB
testcase_24 AC 69 ms
11,392 KB
testcase_25 AC 66 ms
11,388 KB
testcase_26 AC 70 ms
11,392 KB
testcase_27 AC 57 ms
11,392 KB
testcase_28 AC 49 ms
11,264 KB
testcase_29 AC 53 ms
11,392 KB
testcase_30 AC 55 ms
11,392 KB
testcase_31 AC 55 ms
11,392 KB
testcase_32 AC 60 ms
11,260 KB
testcase_33 AC 59 ms
11,264 KB
testcase_34 AC 67 ms
11,392 KB
testcase_35 AC 57 ms
11,264 KB
testcase_36 AC 61 ms
11,364 KB
testcase_37 AC 61 ms
11,264 KB
testcase_38 AC 65 ms
11,264 KB
testcase_39 AC 63 ms
11,264 KB
testcase_40 AC 66 ms
11,264 KB
testcase_41 AC 66 ms
11,392 KB
testcase_42 AC 69 ms
11,264 KB
testcase_43 AC 68 ms
11,264 KB
testcase_44 AC 68 ms
11,264 KB
testcase_45 AC 63 ms
11,264 KB
testcase_46 AC 68 ms
11,264 KB
testcase_47 AC 46 ms
11,360 KB
testcase_48 AC 71 ms
11,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "Main.cpp"
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <atcoder/modint>
#line 1 "nachia\\misc\\bit-operations.hpp"

#line 4 "nachia\\misc\\bit-operations.hpp"


namespace nachia{

    int Popcount(unsigned long long c) noexcept {
    #ifdef __GNUC__
        return __builtin_popcountll(c);
    #else
        c = (c & (~0ull/3)) + ((c >> 1) & (~0ull/3));
        c = (c & (~0ull/5)) + ((c >> 2) & (~0ull/5));
        c = (c & (~0ull/17)) + ((c >> 4) & (~0ull/17));
        c = (c * (~0ull/257)) >> 56;
        return c;
    #endif
    }

    // please ensure x != 0
    int MsbIndex(unsigned long long x) noexcept {
    #ifdef __GNUC__
        return 63 - __builtin_clzll(x);
    #else
        int res = 0;
        for(int d=32; d>=0; d>>=1) if(x >> d){ res |= d; x >>= d; }
        return res;
    #endif
    }

    // please ensure x != 0
    int LsbIndex(unsigned long long x) noexcept {
    #ifdef __GNUC__
        return __builtin_ctzll(x);
    #else
        return msb_idx(x & -x);
    #endif
    }

}

#line 8 "Main.cpp"

using namespace std;
using i64 = long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;

using Modint = atcoder::static_modint<1000000007>;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    const int N = 19;
    int B[N] = {};
    rep(i,N){
        int L; cin >> L;
        rep(j,L){ int a; cin >> a; a--; B[i] |= (1<<a); }
    }
    vector<pair<i64, i64>> dp(1<<N);
    dp[0] = {1,0};
    rep(b,1<<N){
        int k = nachia::Popcount(b);
        rep(i,N) if(!(b&(1<<i))) if(B[k]&(1<<i)){
            int c = nachia::Popcount(b>>i) % 2;
            if(c == 0){
                dp[b|(1<<i)].first += dp[b].first;
                dp[b|(1<<i)].second += dp[b].second;
            }
            else{
                dp[b|(1<<i)].second += dp[b].first;
                dp[b|(1<<i)].first += dp[b].second;
            }
        }
    }
    cout << dp.back().first << " " << dp.back().second << '\n';
    return 0;
}
0