結果
問題 |
No.2152 [Cherry Anniversary 2] 19 Petals of Cherry
|
ユーザー |
👑 ![]() |
提出日時 | 2022-12-09 00:05:57 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 92 ms / 1,000 ms |
コード長 | 2,238 bytes |
コンパイル時間 | 2,378 ms |
コンパイル使用メモリ | 113,708 KB |
最終ジャッジ日時 | 2025-02-09 06:37:27 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 49 |
ソースコード
#line 1 "Main.cpp" #include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <atcoder/modint> #line 1 "nachia\\misc\\bit-operations.hpp" #line 4 "nachia\\misc\\bit-operations.hpp" namespace nachia{ int Popcount(unsigned long long c) noexcept { #ifdef __GNUC__ return __builtin_popcountll(c); #else c = (c & (~0ull/3)) + ((c >> 1) & (~0ull/3)); c = (c & (~0ull/5)) + ((c >> 2) & (~0ull/5)); c = (c & (~0ull/17)) + ((c >> 4) & (~0ull/17)); c = (c * (~0ull/257)) >> 56; return c; #endif } // please ensure x != 0 int MsbIndex(unsigned long long x) noexcept { #ifdef __GNUC__ return 63 - __builtin_clzll(x); #else int res = 0; for(int d=32; d>=0; d>>=1) if(x >> d){ res |= d; x >>= d; } return res; #endif } // please ensure x != 0 int LsbIndex(unsigned long long x) noexcept { #ifdef __GNUC__ return __builtin_ctzll(x); #else return msb_idx(x & -x); #endif } } #line 8 "Main.cpp" using namespace std; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(int)(n); i++) const i64 INF = 1001001001001001001; using Modint = atcoder::static_modint<1000000007>; int main(){ const int N = 19; int B[N] = {}; rep(i,N){ int L; cin >> L; rep(j,L){ int a; cin >> a; a--; B[i] |= (1<<a); } } vector<pair<i64, i64>> dp(1<<N); dp[0] = {1,0}; rep(b,1<<N){ int k = nachia::Popcount(b); rep(i,N) if(!(b&(1<<i))) if(B[k]&(1<<i)){ int c = nachia::Popcount(b>>i) % 2; if(c == 0){ dp[b|(1<<i)].first += dp[b].first; dp[b|(1<<i)].second += dp[b].second; } else{ dp[b|(1<<i)].second += dp[b].first; dp[b|(1<<i)].first += dp[b].second; } } } cout << dp.back().first << " " << dp.back().second << '\n'; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;