結果

問題 No.1958 Bit Game
ユーザー phsplsphspls
提出日時 2022-10-12 11:21:45
言語 Rust
(1.77.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,699 bytes
コンパイル時間 3,804 ms
コンパイル使用メモリ 139,176 KB
実行使用メモリ 9,340 KB
最終ジャッジ日時 2023-09-08 12:17:17
合計ジャッジ時間 10,080 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
9,336 KB
testcase_01 AC 83 ms
9,320 KB
testcase_02 AC 83 ms
9,328 KB
testcase_03 AC 83 ms
9,320 KB
testcase_04 AC 84 ms
9,308 KB
testcase_05 AC 83 ms
9,340 KB
testcase_06 AC 83 ms
9,316 KB
testcase_07 AC 82 ms
9,332 KB
testcase_08 AC 83 ms
9,340 KB
testcase_09 AC 83 ms
9,328 KB
testcase_10 AC 24 ms
4,380 KB
testcase_11 AC 41 ms
5,380 KB
testcase_12 AC 43 ms
6,488 KB
testcase_13 AC 52 ms
5,776 KB
testcase_14 AC 48 ms
5,372 KB
testcase_15 AC 36 ms
7,448 KB
testcase_16 AC 23 ms
5,556 KB
testcase_17 AC 69 ms
8,204 KB
testcase_18 AC 61 ms
8,112 KB
testcase_19 AC 32 ms
6,216 KB
testcase_20 AC 62 ms
5,216 KB
testcase_21 AC 42 ms
7,680 KB
testcase_22 AC 34 ms
4,380 KB
testcase_23 AC 22 ms
4,668 KB
testcase_24 AC 68 ms
7,032 KB
testcase_25 AC 29 ms
4,956 KB
testcase_26 AC 56 ms
5,496 KB
testcase_27 AC 31 ms
6,980 KB
testcase_28 AC 64 ms
6,240 KB
testcase_29 AC 35 ms
4,504 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const MOD: usize = 998244353;
const BITS: usize = 18;

fn main() {
    let mut nxy = String::new();
    std::io::stdin().read_line(&mut nxy).ok();
    let nxy: Vec<usize> = nxy.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nxy[0];
    let x = nxy[1];
    let y = nxy[2];
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let mut b = String::new();
    std::io::stdin().read_line(&mut b).ok();
    let b: Vec<usize> = b.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let mut acnts = vec![vec![0usize; 2]; BITS];
    let mut bcnts = vec![vec![0usize; 2]; BITS];
    for i in 0..x {
        for bit in 0..BITS {
            acnts[bit][(a[i] >> bit) & 1] += 1;
        }
    }
    for i in 0..y {
        for bit in 0..BITS {
            bcnts[bit][(b[i] >> bit) & 1] += 1;
        }
    }
    let mut base = vec![vec![0usize; 2]; BITS];
    for i in 0..BITS { base[i][0] = 1; }
    for _ in 0..n {
        for bidx in 0..BITS {
            (base[bidx][0], base[bidx][1]) = (base[bidx][0] * acnts[bidx][0], base[bidx][1] * (acnts[bidx][0] + acnts[bidx][1]) + base[bidx][0] * acnts[bidx][1]);
            base[bidx][0] %= MOD;
            base[bidx][1] %= MOD;
            (base[bidx][0], base[bidx][1]) = (base[bidx][0] * (bcnts[bidx][0] + bcnts[bidx][1]) + base[bidx][1] * bcnts[bidx][0], base[bidx][1] * bcnts[bidx][1]);
            base[bidx][0] %= MOD;
            base[bidx][1] %= MOD;
        }
    }
    let result = (0..BITS).map(|i| base[i][1] * (1usize << i) % MOD).sum::<usize>() % MOD;
    println!("{}", result);
}
0