結果

問題 No.1689 Set Cards
ユーザー square1001square1001
提出日時 2021-09-24 21:28:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,728 bytes
コンパイル時間 668 ms
コンパイル使用メモリ 73,596 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 20:40:36
合計ジャッジ時間 1,638 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 7 ms
4,376 KB
testcase_12 AC 7 ms
4,376 KB
testcase_13 AC 7 ms
4,376 KB
testcase_14 AC 7 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 6 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 7 ms
4,376 KB
testcase_19 AC 9 ms
4,380 KB
testcase_20 AC 8 ms
4,376 KB
testcase_21 AC 8 ms
4,380 KB
testcase_22 AC 8 ms
4,376 KB
testcase_23 AC 7 ms
4,376 KB
testcase_24 AC 8 ms
4,376 KB
testcase_25 AC 8 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef CLASS_MODINT
#define CLASS_MODINT

#include <cstdint>

template <std::uint32_t mod>
class modint {
private:
	std::uint32_t n;
public:
	modint() : n(0) {};
	modint(std::int64_t n_) : n((n_ >= 0 ? n_ : mod - (-n_) % mod) % mod) {};
	static constexpr std::uint32_t get_mod() { return mod; }
	std::uint32_t get() const { return n; }
	bool operator==(const modint& m) const { return n == m.n; }
	bool operator!=(const modint& m) const { return n != m.n; }
	modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
	modint operator+(const modint& m) const { return modint(*this) += m; }
	modint operator-(const modint& m) const { return modint(*this) -= m; }
	modint operator*(const modint& m) const { return modint(*this) *= m; }
	modint inv() const { return (*this).pow(mod - 2); }
	modint pow(std::uint64_t b) const {
		modint ans = 1, m = modint(*this);
		while (b) {
			if (b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}
};

#endif // CLASS_MODINT

#include <vector>
#include <iostream>
using namespace std;
using mint = modint<998244353>;
int main() {
	int N;
	cin >> N;
	vector<int> b(N);
	for (int i = 0; i < N; ++i) {
		int k, x;
		cin >> k;
		for (int j = 0; j < k; ++j) {
			cin >> x;
			b[i] |= 1 << (x - 1);
		}
	}
	vector<mint> dp(1 << 12);
	dp[(1 << 12) - 1] = 1;
	for (int i = 0; i < N; ++i) {
		vector<mint> ndp(1 << 12);
		for (int j = 0; j < (1 << 12); ++j) {
			ndp[j] += dp[j];
			ndp[j & b[i]] += dp[j];
		}
		dp = ndp;
	}
	cout << dp[0].get() << endl;
	return 0;
}
0