結果

問題 No.2152 [Cherry Anniversary 2] 19 Petals of Cherry
ユーザー tnakao0123tnakao0123
提出日時 2022-12-09 12:08:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 151 ms / 1,000 ms
コード長 1,479 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 45,532 KB
実行使用メモリ 12,032 KB
最終ジャッジ日時 2024-04-22 19:04:04
合計ジャッジ時間 4,896 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,248 KB
testcase_01 AC 7 ms
10,112 KB
testcase_02 AC 3 ms
5,248 KB
testcase_03 AC 98 ms
11,932 KB
testcase_04 AC 39 ms
9,984 KB
testcase_05 AC 124 ms
11,776 KB
testcase_06 AC 37 ms
10,368 KB
testcase_07 AC 70 ms
9,984 KB
testcase_08 AC 97 ms
11,392 KB
testcase_09 AC 19 ms
11,904 KB
testcase_10 AC 106 ms
11,752 KB
testcase_11 AC 55 ms
11,904 KB
testcase_12 AC 16 ms
10,496 KB
testcase_13 AC 40 ms
9,728 KB
testcase_14 AC 73 ms
10,880 KB
testcase_15 AC 74 ms
10,240 KB
testcase_16 AC 70 ms
11,136 KB
testcase_17 AC 92 ms
11,812 KB
testcase_18 AC 96 ms
11,864 KB
testcase_19 AC 88 ms
11,804 KB
testcase_20 AC 6 ms
5,376 KB
testcase_21 AC 110 ms
12,032 KB
testcase_22 AC 41 ms
11,980 KB
testcase_23 AC 47 ms
9,600 KB
testcase_24 AC 123 ms
11,792 KB
testcase_25 AC 97 ms
11,648 KB
testcase_26 AC 72 ms
11,800 KB
testcase_27 AC 56 ms
11,776 KB
testcase_28 AC 5 ms
5,376 KB
testcase_29 AC 5 ms
5,376 KB
testcase_30 AC 5 ms
5,376 KB
testcase_31 AC 6 ms
6,144 KB
testcase_32 AC 9 ms
7,936 KB
testcase_33 AC 14 ms
9,856 KB
testcase_34 AC 23 ms
11,136 KB
testcase_35 AC 39 ms
11,648 KB
testcase_36 AC 60 ms
11,904 KB
testcase_37 AC 83 ms
11,864 KB
testcase_38 AC 104 ms
11,904 KB
testcase_39 AC 122 ms
11,856 KB
testcase_40 AC 136 ms
11,752 KB
testcase_41 AC 144 ms
11,776 KB
testcase_42 AC 150 ms
11,860 KB
testcase_43 AC 151 ms
11,776 KB
testcase_44 AC 148 ms
11,776 KB
testcase_45 AC 148 ms
11,776 KB
testcase_46 AC 147 ms
11,772 KB
testcase_47 AC 4 ms
5,376 KB
testcase_48 AC 109 ms
11,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2152.cc:  No.2152 [Cherry Anniversary 2]  19 Petals of Cherry - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int N = 19;
const int NBITS = 1 << N;
const int BN = (N + 1) / 2;
const int BBITS = 1 << BN;

/* typedef */

typedef long long ll;

/* global variables */

int bnums[BBITS], bs[N];
ll dp[NBITS][2];

/* subroutines */

inline int bitnum(int bits) {
  return bnums[bits >> BN] + bnums[bits & (BBITS - 1)];
}

int invcnt(int bits, int i) {
  int c = 0;
  for (int j = i + 1, bj = 1 << j; j < N; j++, bj <<= 1)
    if (bits & bj) c++;
  return c;
}

/* main */

int main() {
  bnums[0] = 0;
  for (int bits = 1, msb = 1; bits < BBITS; bits++) {
    if ((msb << 1) <= bits) msb <<= 1;
    bnums[bits] = bnums[bits ^ msb] + 1;
  }

  for (int i = 0; i < N; i++) {
    int li;
    scanf("%d", &li);
    for (int j = 0; j < li; j++) {
      int aij;
      scanf("%d", &aij), aij--;
      bs[i] |= (1 << aij);
    }
    //printf("bs[%d] = %d\n", i, bs[i]);
  }

  dp[0][0] = 1;

  for (int bits = 0; bits < NBITS - 1; bits++) {
    int b = bs[bitnum(bits)];
    
    for (int j = 0; j < 2; j++)
      if (dp[bits][j] > 0)
	for (int i = 0, bi = 1; i < N; i++, bi <<= 1)
	  if (! (bits & bi) && (b & bi)) {
	    int invc = invcnt(bits, i);
	    int j1 = (j + invc) & 1;
	    dp[bits | bi][j1] += dp[bits][j];
	  }
      }

  printf("%lld %lld\n", dp[NBITS - 1][0], dp[NBITS - 1][1]);
  return 0;
}
0