結果

問題 No.2152 [Cherry Anniversary 2] 19 Petals of Cherry
ユーザー 👑 emthrmemthrm
提出日時 2022-12-09 00:15:26
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 1,000 ms
コード長 1,752 bytes
コンパイル時間 1,930 ms
コンパイル使用メモリ 199,584 KB
実行使用メモリ 19,956 KB
最終ジャッジ日時 2023-08-04 20:34:27
合計ジャッジ時間 8,587 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
19,776 KB
testcase_01 AC 102 ms
19,800 KB
testcase_02 AC 83 ms
19,716 KB
testcase_03 AC 94 ms
19,724 KB
testcase_04 AC 102 ms
19,736 KB
testcase_05 AC 99 ms
19,724 KB
testcase_06 AC 101 ms
19,956 KB
testcase_07 AC 102 ms
19,784 KB
testcase_08 AC 105 ms
19,704 KB
testcase_09 AC 100 ms
19,944 KB
testcase_10 AC 101 ms
19,764 KB
testcase_11 AC 103 ms
19,840 KB
testcase_12 AC 99 ms
19,740 KB
testcase_13 AC 101 ms
19,748 KB
testcase_14 AC 101 ms
19,700 KB
testcase_15 AC 106 ms
19,720 KB
testcase_16 AC 101 ms
19,780 KB
testcase_17 AC 104 ms
19,752 KB
testcase_18 AC 100 ms
19,740 KB
testcase_19 AC 101 ms
19,808 KB
testcase_20 AC 102 ms
19,740 KB
testcase_21 AC 102 ms
19,840 KB
testcase_22 AC 103 ms
19,904 KB
testcase_23 AC 104 ms
19,748 KB
testcase_24 AC 103 ms
19,748 KB
testcase_25 AC 101 ms
19,704 KB
testcase_26 AC 98 ms
19,828 KB
testcase_27 AC 100 ms
19,808 KB
testcase_28 AC 89 ms
19,708 KB
testcase_29 AC 91 ms
19,820 KB
testcase_30 AC 97 ms
19,760 KB
testcase_31 AC 101 ms
19,744 KB
testcase_32 AC 101 ms
19,744 KB
testcase_33 AC 99 ms
19,740 KB
testcase_34 AC 99 ms
19,836 KB
testcase_35 AC 97 ms
19,780 KB
testcase_36 AC 100 ms
19,740 KB
testcase_37 AC 101 ms
19,716 KB
testcase_38 AC 104 ms
19,736 KB
testcase_39 AC 106 ms
19,704 KB
testcase_40 AC 111 ms
19,944 KB
testcase_41 AC 104 ms
19,816 KB
testcase_42 AC 102 ms
19,740 KB
testcase_43 AC 100 ms
19,748 KB
testcase_44 AC 97 ms
19,700 KB
testcase_45 AC 95 ms
19,760 KB
testcase_46 AC 97 ms
19,760 KB
testcase_47 AC 87 ms
19,800 KB
testcase_48 AC 103 ms
19,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  constexpr int N = 19;
  bool exist[N][N]{};
  REP(i, N) {
    int l; cin >> l;
    while (l--) {
      int a; cin >> a; --a;
      exist[i][a] = true;
    }
  }
  ll dp[2][1 << N]{}, nxt[2][1 << N]{};
  REP(i, N) {
    if (exist[i][0]) dp[i & 1][1 << i] = 1;
  }
  FOR(s, 1, N) {
    REP(i, 2) fill(nxt[i], nxt[i] + (1 << N), 0);
    for (int subset = (1 << s) - 1; subset < (1 << N);) {
      int parity = 0;
      REP(i, N) {
        if (subset >> i & 1) continue;
        if (exist[i][s]) {
          REP(j, 2) nxt[j ^ parity][subset | (1 << i)] += dp[j][subset];
        }
        parity ^= 1;
      }
      const int tmp1 = subset & -subset, tmp2 = subset + tmp1;
      subset = (((subset & ~tmp2) / tmp1) >> 1) | tmp2;
    }
    swap(dp, nxt);
  }
  cout << dp[0][(1 << N) - 1] << ' ' << dp[1][(1 << N) - 1] << '\n';
  return 0;
}
0