結果

問題 No.1958 Bit Game
ユーザー trineutrontrineutron
提出日時 2022-05-27 21:50:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 283 ms / 2,000 ms
コード長 1,789 bytes
コンパイル時間 2,147 ms
コンパイル使用メモリ 210,260 KB
実行使用メモリ 5,388 KB
最終ジャッジ日時 2023-10-20 20:09:18
合計ジャッジ時間 9,793 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 277 ms
5,388 KB
testcase_01 AC 270 ms
5,388 KB
testcase_02 AC 279 ms
5,388 KB
testcase_03 AC 274 ms
5,388 KB
testcase_04 AC 277 ms
5,388 KB
testcase_05 AC 273 ms
5,388 KB
testcase_06 AC 283 ms
5,388 KB
testcase_07 AC 274 ms
5,388 KB
testcase_08 AC 279 ms
5,388 KB
testcase_09 AC 282 ms
5,388 KB
testcase_10 AC 69 ms
4,348 KB
testcase_11 AC 133 ms
4,348 KB
testcase_12 AC 157 ms
4,596 KB
testcase_13 AC 154 ms
4,348 KB
testcase_14 AC 137 ms
4,348 KB
testcase_15 AC 171 ms
4,860 KB
testcase_16 AC 109 ms
4,348 KB
testcase_17 AC 238 ms
5,124 KB
testcase_18 AC 211 ms
4,860 KB
testcase_19 AC 134 ms
4,596 KB
testcase_20 AC 162 ms
4,348 KB
testcase_21 AC 184 ms
4,860 KB
testcase_22 AC 79 ms
4,348 KB
testcase_23 AC 88 ms
4,348 KB
testcase_24 AC 206 ms
4,596 KB
testcase_25 AC 101 ms
4,348 KB
testcase_26 AC 154 ms
4,348 KB
testcase_27 AC 155 ms
4,596 KB
testcase_28 AC 189 ms
4,596 KB
testcase_29 AC 95 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/modint>

using namespace std;
using namespace atcoder;

using mint = modint998244353;

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    vector<int> a(x), b(y);
    for (int i = 0; i < x; i++) {
        cin >> a.at(i);
    }
    for (int i = 0; i < y; i++) {
        cin >> b.at(i);
    }

    vector<mint> cx0(18), cx1(18), cy0(18), cy1(18);
    for (int i = 0; i < x; i++) {
        for (int j = 0; j < 18; j++) {
            if (a.at(i) >> j & 1) {
                cx1.at(j)++;
            } else {
                cx0.at(j)++;
            }
        }
    }
    for (int i = 0; i < y; i++) {
        for (int j = 0; j < 18; j++) {
            if (b.at(i) >> j & 1) {
                cy1.at(j)++;
            } else {
                cy0.at(j)++;
            }
        }
    }

    vector<mint> cp0(18, 1), cp1(18);
    for (int i = 0; i < 2 * n; i++) {
        vector<mint> cp0_new(18), cp1_new(18);
        if (i % 2 == 0) {
            for (int j = 0; j < 18; j++) {
                cp0_new.at(j) += cp0.at(j) * cx0.at(j);
                cp1_new.at(j) += cp0.at(j) * cx1.at(j);
                cp1_new.at(j) += cp1.at(j) * cx0.at(j);
                cp1_new.at(j) += cp1.at(j) * cx1.at(j);
            }
        } else {
            for (int j = 0; j < 18; j++) {
                cp0_new.at(j) += cp0.at(j) * cy0.at(j);
                cp0_new.at(j) += cp0.at(j) * cy1.at(j);
                cp0_new.at(j) += cp1.at(j) * cy0.at(j);
                cp1_new.at(j) += cp1.at(j) * cy1.at(j);
            }
        }
        swap(cp0, cp0_new);
        swap(cp1, cp1_new);
    }

    mint ans = 0;
    for (int i = 18 - 1; i >= 0; i--) {
        ans *= 2;
        ans += cp1.at(i);
    }
    cout << ans.val() << endl;

    return 0;
}
0