結果

問題 No.2152 [Cherry Anniversary 2] 19 Petals of Cherry
ユーザー chro_96
提出日時 2022-12-09 01:05:18
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 74 ms / 1,000 ms
コード長 827 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 30,464 KB
実行使用メモリ 17,408 KB
最終ジャッジ日時 2024-10-14 18:23:02
合計ジャッジ時間 4,622 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main () {
  int l = 0;
  int a = 0;
  
  int res = 0;
  
  long long dp[1000000][2] = {};
  
  int a_set[19] = {};
  
  for (int i = 0; i < 19; i++) {
    res = scanf("%d", &l);
    for (int j = 0; j < l; j++) {
      res = scanf("%d", &a);
      a_set[i] |= (1<<(a-1));
    }
  }
  
  dp[0][0] = 1LL;
  for (int i = 0; i < (1<<19)-1; i++) {
    int cnt = 0;
    int gt_num = 0;
    for (int j = 0; j < 19; j++) {
      if ((i&(1<<j)) > 0) {
        cnt++;
      }
    }
    for (int j = 18; j >= 0; j--) {
      if ((i&(1<<j)) > 0) {
        gt_num++;
      } else if ((a_set[cnt]&(1<<j)) > 0) {
        int idx = (i|(1<<j));
        dp[idx][0] += dp[i][gt_num%2];
        dp[idx][1] += dp[i][1-gt_num%2];
      }
    }
  }
  
  printf("%lld %lld\n", dp[(1<<19)-1][0], dp[(1<<19)-1][1]);
  return 0;
}
0