結果

問題 No.2152 [Cherry Anniversary 2] 19 Petals of Cherry
ユーザー umezo
提出日時 2022-12-09 00:56:32
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 164 ms / 1,000 ms
コード長 866 bytes
コンパイル時間 2,162 ms
コンパイル使用メモリ 196,564 KB
最終ジャッジ日時 2025-02-09 06:42:12
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

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

ll dp[20][530000][2];
int B[1<<19][20];
int x=(1<<19)-1;
vector<int> A[20];
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  for(int i=0;i<(1<<19);i++){
    int cnt=0;
    for(int j=18;j>=0;j--){
      if(i&(1<<j)) cnt++;
      B[i][j]=cnt;
    }
  }
  
  rep(i,19){
    int l;
    cin>>l;
    rep(_,l){
      int a;
      cin>>a;
      a--;
      A[i+1].push_back(a);
    }
  }
  
  dp[0][0][0]=1;
  for(int i=1;i<=19;i++){
    rep(j,1<<19){
      if(__builtin_popcount(j)!=i-1) continue;
      for(auto a:A[i]){
        if(j&(1<<a)) continue;
        rep(k,2) dp[i][j|(1<<a)][(k+B[j][a+1])%2]+=dp[i-1][j][k];
      }
    }
  }
  cout<<dp[19][x][0]<<" "<<dp[19][x][1]<<endl;
  
  return 0;
}
0