結果

問題 No.2152 [Cherry Anniversary 2] 19 Petals of Cherry
ユーザー roaris
提出日時 2022-12-09 01:18:48
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 989 bytes
コンパイル時間 1,906 ms
コンパイル使用メモリ 192,948 KB
最終ジャッジ日時 2025-02-09 06:44:06
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35 TLE * 14
権限があれば一括ダウンロードができます

ソースコード

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) rep(i, N) {
        for (int j=i+1; j<N; j++) if ((S>>j)&1) inv[S][i]++;
    }
    
    rep(t, N) {
        ll ndp[1<<N][2];
        rep(S, 1<<N) rep(i, 2) ndp[S][i] = 0ll;
        int L; cin >> L;
        
        while (L--) {
            int A; cin >> A; A--;
            rep(S, 1<<N) {
                if ((S>>A)&1) continue;
                ndp[S|(1<<A)][inv[S][A]%2] += dp[S][0];
                ndp[S|(1<<A)][(inv[S][A]%2+1)%2] += dp[S][1];
            }
        }
        
        rep(S, 1<<N) rep(i, 2) dp[S][i] = ndp[S][i];
    }
    
    cout << dp[(1<<N)-1][0] << " " << dp[(1<<N)-1][1] << endl;
}
0