結果

問題 No.1189 Sum is XOR
ユーザー IKyoproIKyopro
提出日時 2020-08-22 13:47:37
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 2,231 bytes
コンパイル時間 2,226 ms
コンパイル使用メモリ 199,324 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 08:12:38
合計ジャッジ時間 3,324 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
6,812 KB
testcase_01 AC 17 ms
6,944 KB
testcase_02 AC 18 ms
6,940 KB
testcase_03 AC 9 ms
6,944 KB
testcase_04 AC 8 ms
6,944 KB
testcase_05 AC 12 ms
6,940 KB
testcase_06 AC 16 ms
6,940 KB
testcase_07 AC 10 ms
6,940 KB
testcase_08 AC 5 ms
6,944 KB
testcase_09 AC 5 ms
6,944 KB
testcase_10 AC 5 ms
6,940 KB
testcase_11 AC 6 ms
6,940 KB
testcase_12 AC 17 ms
6,940 KB
testcase_13 AC 15 ms
6,940 KB
testcase_14 AC 11 ms
6,944 KB
testcase_15 AC 7 ms
6,940 KB
testcase_16 AC 6 ms
6,940 KB
testcase_17 AC 6 ms
6,940 KB
testcase_18 AC 7 ms
6,940 KB
testcase_19 AC 13 ms
6,940 KB
testcase_20 AC 14 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template <class T> using vvvec = vector<vvec<T>>;

constexpr ll mod = 998244353;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    
    friend ostream &operator<<(ostream& os,const mint& a){
        return os << a.x;
    }

    friend istream &operator>>(istream& is,mint& a){
        ll t;
        is >> t;
        a = mint(t);
        return (is);
    }

    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(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    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;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K;
    cin >> N >> K;
    int B = 10;
    vec<mint> cnt(1<<10);
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        cnt[a] += 1;
    }
    vec<mint> dp(1<<B);
    if(K>(1<<B)){
        cout << 0 << "\n";
        return 0;
    }
    dp[0] = 1;
    for(int i=0;i<K;i++){
        vec<mint> ndp(1<<B);
        for(int S=0;S<(1<<B);S++){
            for(int T=S;T>=0;T=S&(T-1)){
                ndp[S] += dp[T]*cnt[T^S];
                if(!T) break;
            }
        }
        dp.swap(ndp);
    }
    mint ans = accumulate(dp.begin(),dp.end(),(mint) 0);
    for(int i=1;i<=K;i++) ans /= i;
    cout << ans << "\n";
}
0