結果

問題 No.1689 Set Cards
ユーザー zawakasuzawakasu
提出日時 2022-08-28 03:40:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 3,091 bytes
コンパイル時間 3,102 ms
コンパイル使用メモリ 223,084 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 04:13:50
合計ジャッジ時間 4,315 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define all(x) begin(x), end(x)

using namespace std;
using i32 = int;
using i64 = long long;
using ld = long double;

template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b and (a = b, true);}

template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b and (a = b, true);}

const i64 supl = LONG_LONG_MAX / 2 - 100;
const i32 supi = INT_MAX / 2 - 100;

namespace zawa {

    template<long long mod>
    class modint {
    private:
        long long x;

    public:
        modint() : x(0) {}
        
        modint(long long x) : x((x % mod + mod) % mod) {}

        modint& operator+=(modint p) {
            x += p.x;
            if (x >= mod) x -= mod;
            return *this;
        }

        modint& operator-=(modint p) {
            x += mod - p.x;
            if (x >= mod) x -= mod;
            return *this;
        }

        modint& operator*=(modint p) {
            x = (1LL * x * p.x % mod);
            return *this;
        }

        modint& operator/=(modint p) {
            *this *= p.inv();
            return *this;
        }

        modint operator-() const {
            return modint(-x);
        }

        modint operator+(const modint& p) const {
            return modint(*this) += p;
        }

        modint operator-(const modint& p) const {
            return modint(*this) -= p;
        }

        modint operator*(const modint& p) const {
            return modint(*this) *= p;
        }

        modint operator/(const modint& p) const {
            return modint(*this) /= p;
        }

        long long val() {
            return x;
        }

        modint pow(long long p) {
            modint res(1), val(x);
            while(p) {
                if (p & 1) res *= val;
                val *= val;
                p >>= 1;
            }
            return res;
        }

        modint inv() {
            return pow(mod - 2);
        }
    };

}// namespace zawa

using mint = zawa::modint<998244353>;

void main_() {
    i32 n; cin >> n;
    vector<i32> as(n);
    for (auto& a : as) {
        i32 k; cin >> k;
        for (i32 _ = 0 ; _ < k ; _++) {
            i32 c; cin >> c;
            c--;
            a = a | (1 << c);
        }
    }

    vector<mint> ps(n + 1, mint(1));
    for (i32 i = 1 ; i <= n ; i++) ps[i] = ps[i - 1] * 2;

    mint ans = ps[n] - 1;
    for (i32 bit = 1 ; bit < (1 << 12) ; bit++) {
        int cnt = 0;
        for (i32 i = 0 ; i < n ; i++) {
            bool ok = true;
            for (i32 j = 0 ; j < 12 ; j++) {
                if (!(bit & (1 << j))) continue;
                if (!(as[i] & (1 << j))) ok = false;
            }
            if (ok) cnt++;
        }
        // cout << bit << ' ' << cnt << endl;
        ans -= (__builtin_popcount(bit) & 1 ? ps[cnt] - 1 : -(ps[cnt] - 1));
    }
    cout << ans.val() << endl;
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    main_();

    return 0;
}
0