結果

問題 No.1189 Sum is XOR
ユーザー tomatoma
提出日時 2020-08-22 16:52:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 2,966 bytes
コンパイル時間 2,375 ms
コンパイル使用メモリ 206,596 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 10:58:36
合計ジャッジ時間 4,310 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
6,820 KB
testcase_01 AC 67 ms
6,944 KB
testcase_02 AC 64 ms
6,944 KB
testcase_03 AC 29 ms
6,940 KB
testcase_04 AC 27 ms
6,940 KB
testcase_05 AC 43 ms
6,944 KB
testcase_06 AC 61 ms
6,944 KB
testcase_07 AC 35 ms
6,944 KB
testcase_08 AC 16 ms
6,940 KB
testcase_09 AC 15 ms
6,940 KB
testcase_10 AC 13 ms
6,944 KB
testcase_11 AC 20 ms
6,940 KB
testcase_12 AC 64 ms
6,940 KB
testcase_13 AC 62 ms
6,940 KB
testcase_14 AC 42 ms
6,940 KB
testcase_15 AC 23 ms
6,944 KB
testcase_16 AC 20 ms
6,940 KB
testcase_17 AC 20 ms
6,944 KB
testcase_18 AC 26 ms
6,940 KB
testcase_19 AC 53 ms
6,944 KB
testcase_20 AC 55 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
struct ModInt {
    static const ll MOD = 998244353;

    // constructors etc
    ModInt() :num(1ll) {}
    ModInt(ll num_) :num(num_%MOD) {}
    ModInt(const ModInt& modint) :num(modint.num%MOD) {}
    ll get()const { return num; }

    // operator etc
    // operator ll() const { return num; }
    // ll operator*() { return num; }
    ModInt& operator+=(const ModInt& r) { (num += r.num) %= MOD; return *this; }
    ModInt& operator-=(const ModInt& r) { (num += -r.num + MOD) %= MOD; return *this; }
    ModInt& operator*=(const ModInt& r) { (num *= r.num) %= MOD; return *this; }
    ModInt& operator/=(const ModInt& r) { (num *= r.inv().num) %= MOD; return *this; }
    ModInt pow(const ModInt& r)const {
        ll res = 1;
        ll x = num;
        ll n = r.num;
        while (n > 0) {
            if (n & 1)res = (res*x) % MOD;
            x = (x*x) % MOD;
            n >>= 1;
        }
        return res;
    }
    ModInt inv()const { return this->pow(MOD - 2); }

    ModInt operator+(const ModInt& r)const { return ModInt(*this) += r; }
    ModInt operator-(const ModInt& r)const { return ModInt(*this) -= r; }
    ModInt operator*(const ModInt& r)const { return ModInt(*this) *= r; }
    ModInt operator/(const ModInt& r)const { return ModInt(*this) /= r; }
    ModInt operator+(const ll& r)const { return *this + ModInt(r); }
    ModInt operator-(const ll& r)const { return *this - ModInt(r); }
    ModInt operator*(const ll& r)const { return *this * ModInt(r); }
    ModInt operator/(const ll& r)const { return *this / ModInt(r); }

private:
    ll num;
};
ostream& operator<<(ostream& stream, const ModInt& val) { stream << val.get(); return stream; }

// ============ template finished ============

int main()
{
    int N, K;
    cin >> N >> K;
    map<int, int> A;
    rep(i, N) {
        int a;
        cin >> a;
        A[a]++;
    }
    if (K > 10) {
        cout << 0 << endl;
        return 0;
    }

    const int LIM = 1 << 10;
    vector<ModInt> zero(LIM, ModInt(0));
    auto dp = zero;
    dp[0] = 1;
    rep(i, K) {
        auto next = zero;
        for (auto itr : A) {
            const auto[num, times] = itr;
            rep(i, LIM)if ((i&num) == 0) {
                next[i | num] += dp[i] * times;
            }
        }
        dp = next;
        if (i == 0)dp[0] = 0;
    }

    ModInt total(0);
    for (auto num : dp)total += num;
    REP(i, 1, K + 1)total /= i;
    cout << total << endl;
    return 0;
}
0