結果

問題 No.1189 Sum is XOR
ユーザー ha71ha71
提出日時 2020-09-22 16:55:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 1,736 bytes
コンパイル時間 1,801 ms
コンパイル使用メモリ 166,672 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-08 13:17:33
合計ジャッジ時間 4,181 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
4,380 KB
testcase_01 AC 104 ms
4,376 KB
testcase_02 AC 102 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 72 ms
4,380 KB
testcase_12 AC 102 ms
4,380 KB
testcase_13 AC 95 ms
4,376 KB
testcase_14 AC 84 ms
4,380 KB
testcase_15 AC 73 ms
4,384 KB
testcase_16 AC 68 ms
4,380 KB
testcase_17 AC 72 ms
4,376 KB
testcase_18 AC 77 ms
4,376 KB
testcase_19 AC 92 ms
4,380 KB
testcase_20 AC 91 ms
4,380 KB
testcase_21 AC 65 ms
4,380 KB
testcase_22 AC 65 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include "atcoder/all"
typedef long long int ll;
using namespace std;
// using namespace atcoder;
#define MAXN 1024
#define mod 998244353
ll Pow(ll a, ll n) {
    if (n == 0) return 1;
    if (n % 2) return (a * Pow(a, n - 1)) % mod;
    else {
        ll k = Pow(a, n / 2);
        return (k * k) % mod;
    }
}
ll gyakusuu[MAXN + 1];
ll cnt[MAXN];
ll dp[MAXN][11];
int main() {
    for (int i = 1; i <= MAXN; i++) {
        gyakusuu[i] = Pow(i, mod - 2);
    }
    ll n, K;
    cin >> n >> K;
    if (K >= 11) {
        cout << 0 << endl;
        return 0;
    }
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        cnt[a]++;
    }
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for (int i = 0; i < 1024; i++) {
        for (int j = 0; j < 1024; j++) {
            // p xor i = j とななるような p
            ll count = 1;
            ll p = 0;
            bool ok = true;
            ll i1 = i;
            ll j1 = j;
            for (int k = 1; k <= 10; k++) {
                if ((j1 % 2 == 0)&&(i1 % 2 == 1)) {
                    ok = false;
                }
                else if ((j1 % 2 == 1)&&(i1 % 2 == 0)) {
                    p += count;
                }
                count *= 2;
                i1 /= 2;
                j1 /= 2;
            }
            if (ok) {
                for (int k = 1; k <= 10; k++) {
                    dp[j][k] = (dp[j][k] + dp[i][k - 1] * cnt[p]) % mod;
                }
            }
        }
    }
    ll ret = 0;
    for (int i = 1; i <= 1023; i++) {
        ret = (ret + dp[i][K]) % mod;
    }
    for (int i = 1; i <= K; i++) {
        ret = ret * gyakusuu[i] % mod;
    }
    cout << ret << endl;
    return 0;
}
0