結果

問題 No.2152 [Cherry Anniversary 2] 19 Petals of Cherry
ユーザー roarisroaris
提出日時 2022-12-09 01:44:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 144 ms / 1,000 ms
コード長 1,191 bytes
コンパイル時間 2,929 ms
コンパイル使用メモリ 203,408 KB
実行使用メモリ 52,712 KB
最終ジャッジ日時 2023-08-04 20:44:42
合計ジャッジ時間 10,157 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
52,500 KB
testcase_01 AC 107 ms
52,608 KB
testcase_02 AC 73 ms
52,616 KB
testcase_03 AC 123 ms
52,620 KB
testcase_04 AC 109 ms
52,428 KB
testcase_05 AC 117 ms
52,468 KB
testcase_06 AC 115 ms
52,648 KB
testcase_07 AC 117 ms
52,532 KB
testcase_08 AC 119 ms
52,380 KB
testcase_09 AC 112 ms
52,464 KB
testcase_10 AC 114 ms
52,620 KB
testcase_11 AC 115 ms
52,432 KB
testcase_12 AC 114 ms
52,616 KB
testcase_13 AC 112 ms
52,648 KB
testcase_14 AC 123 ms
52,692 KB
testcase_15 AC 115 ms
52,708 KB
testcase_16 AC 113 ms
52,536 KB
testcase_17 AC 118 ms
52,460 KB
testcase_18 AC 124 ms
52,408 KB
testcase_19 AC 118 ms
52,636 KB
testcase_20 AC 108 ms
52,380 KB
testcase_21 AC 109 ms
52,616 KB
testcase_22 AC 119 ms
52,572 KB
testcase_23 AC 110 ms
52,540 KB
testcase_24 AC 120 ms
52,536 KB
testcase_25 AC 113 ms
52,616 KB
testcase_26 AC 120 ms
52,640 KB
testcase_27 AC 103 ms
52,712 KB
testcase_28 AC 91 ms
52,628 KB
testcase_29 AC 95 ms
52,504 KB
testcase_30 AC 98 ms
52,376 KB
testcase_31 AC 100 ms
52,680 KB
testcase_32 AC 109 ms
52,684 KB
testcase_33 AC 110 ms
52,412 KB
testcase_34 AC 109 ms
52,380 KB
testcase_35 AC 112 ms
52,496 KB
testcase_36 AC 115 ms
52,412 KB
testcase_37 AC 110 ms
52,428 KB
testcase_38 AC 121 ms
52,428 KB
testcase_39 AC 117 ms
52,404 KB
testcase_40 AC 119 ms
52,708 KB
testcase_41 AC 119 ms
52,492 KB
testcase_42 AC 125 ms
52,608 KB
testcase_43 AC 129 ms
52,412 KB
testcase_44 AC 137 ms
52,540 KB
testcase_45 AC 136 ms
52,376 KB
testcase_46 AC 144 ms
52,692 KB
testcase_47 AC 76 ms
52,500 KB
testcase_48 AC 119 ms
52,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
typedef long long ll;

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    
    int N = 19;
    ll dp[1<<N][2];
    rep(S, 1<<N) rep(i, 2) dp[S][i] = 0ll;
    dp[0][0] = 1ll;
    
    int inv[1<<N][N];
    rep(S, 1<<N) rep(i, N) inv[S][i] = 0;
    rep(S, 1<<N) {
        int cnt[N]; fill(cnt, cnt+N, 0);
        rep(i, N) if ((S>>i)&1) cnt[i] = 1;
        for (int i=1; i<N; i++) cnt[i] += cnt[i-1];
        rep(i, N) inv[S][i] = N-cnt[i];
    }
    
    vector<int> bits[N+1];
    rep(S, 1<<N) {
        int c = 0;
        rep(i, N) if ((S>>i)&1) c++;
        bits[c].pb(S);
    }
    rep(i, N) reverse(bits[i].begin(), bits[i].end());
    
    rep(t, N) {
        int L; cin >> L;
        int A[L]; rep(i, L) cin >> A[i];
        rep(i, L) A[i]--;
        for (int S : bits[t]) {
            for (int Ai: A) {
                if ((S>>Ai)&1) continue;
                dp[S|(1<<Ai)][inv[S][Ai]%2] += dp[S][0];
                dp[S|(1<<Ai)][(inv[S][Ai]%2+1)%2] += dp[S][1];
            }
        }
    }
    
    cout << dp[(1<<N)-1][0] << " " << dp[(1<<N)-1][1] << endl;
}
0