結果
問題 |
No.2152 [Cherry Anniversary 2] 19 Petals of Cherry
|
ユーザー |
![]() |
提出日時 | 2022-12-09 19:49:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 107 ms / 1,000 ms |
コード長 | 933 bytes |
コンパイル時間 | 4,062 ms |
コンパイル使用メモリ | 252,788 KB |
最終ジャッジ日時 | 2025-02-09 06:54:43 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 49 |
ソースコード
// #include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; using ll = long long; #define rep(i, n) for (int i=0; i<(int)(n); ++(i)) #define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i)) #define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i)) #define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i)) #define all(x) (x).begin(), (x).end() const int INF = (int)(1e9); int main() { int n = 19; vector<int> a(n); rep(i, n) { int li; cin >> li; rep(j, li) { int ai; cin >> ai; --ai; a[i] |= 1 << ai; } } vector<vector<ll>> dp(1<<n, vector<ll>(2)); dp[0][0] = 1; rep(i, (1<<n)-1) { int bi = __builtin_popcount(i); rep(j, n) if ((a[bi]&(1<<j)) && !(i&(1<<j))) { int add = __builtin_popcount(i&(-(1<<(j+1)))) % 2; rep(j2, 2) dp[i|(1<<j)][(j2+add)%2] += dp[i][j2]; } } cout << dp[(1<<n)-1][0] << ' ' << dp[(1<<n)-1][1] << endl; return 0; }