結果

問題 No.2134 $\sigma$-algebra over Finite Set
ユーザー momoyuumomoyuu
提出日時 2023-04-23 15:04:59
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,773 bytes
コンパイル時間 3,689 ms
コンパイル使用メモリ 275,908 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 11:12:37
合計ジャッジ時間 5,252 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 14 ms
5,376 KB
testcase_11 AC 14 ms
5,376 KB
testcase_12 AC 48 ms
5,376 KB
testcase_13 AC 108 ms
5,376 KB
testcase_14 AC 9 ms
5,376 KB
testcase_15 AC 14 ms
5,376 KB
testcase_16 AC 11 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
struct unionfind{
    int n;
    vector<int> parent;
    vector<int> num;

    unionfind(int n):n(n),parent(vector<int>(n)),num(vector<int>(n,1)){
        for(int i = 0; i < n; i++) parent[i] = i;
    }

    int find(int n){
        if (parent[n] == n) return n;
        parent[n] = find(parent[n]);
        return parent[n];
    }

    int merge(int n,int m){
        n = find(n);
        m = find(m);
        if (n==m) return n;
        if (num[n]>num[m]) return merge(m,n);
        parent[m] = n;
        num[n] += num[m];
        return n;
    }

    int getnum(int n){
        return num[find(n)];
    }
};

const ll mod = 998'244'353;
//const ll mod = 1'000'000'007;
//const ll mod = 67'280'421'310'721;
struct mint{
    long long x;
    mint(long long x=0):x((x%mod+mod)%mod){}
    mint operator-() const{
        return mint(-x);
    }
    mint& operator+=(const mint& a){
        if((x+=a.x)>=mod)x-=mod;
        return *this;
    }
    mint& operator-=(const mint& a){
        if((x+=mod-a.x)>=mod)x-=mod;
        return *this;
    }
    mint& operator*=(const  mint& a){
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const{
        mint res(*this);
        return res*=a;
    }
    mint pow(long long n) const {
        assert(0 <= n);
        mint a = *this, r = 1;
        while (n) {
            if (n & 1) r *= a;
            a *= a;
            n >>= 1;
        }
        return r;
    }
    mint inv() const{
        return pow(mod-2);
    }
    mint& operator/=(const mint& a){
        return (*this)*=a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
    bool operator==(const mint& a) const {
        return x == a.x;
    }
    bool operator<(const mint& a) const{
        return x < a.x;
    }
};

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> c1(n,0),c2(n,0);
    for(int i = 0;i<m;i++){
        int l;
        cin>>l;
        vector<int> cc(n,0);
        for(int j = 0;j<l;j++){
            int a;
            cin>>a;
            a--;
            c1[a]++;
            cc[a]++;
        }
        for(int j = 0;j<n;j++) if(cc[j]==0) c2[j]++;
    }
    int a = 0,b = 0;
    for(int i = 0;i<n;i++) if(c1[i]==m) a++;
    for(int i = 0;i<n;i++) if(c2[i]==m) b++;
    int need = n - max(0,a-1) - max(0,b-1);
    if(need<=1) cout<<4<<endl;
    else cout<<mint(2).pow(need)<<endl;
}

0