結果

問題 No.1142 XOR と XOR
ユーザー koba-e964koba-e964
提出日時 2021-09-18 11:16:46
言語 Rust
(1.77.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 2,272 bytes
コンパイル時間 1,184 ms
コンパイル使用メモリ 152,948 KB
実行使用メモリ 6,704 KB
最終ジャッジ日時 2023-08-07 22:30:23
合計ジャッジ時間 3,254 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 52 ms
6,612 KB
testcase_04 AC 36 ms
5,912 KB
testcase_05 AC 30 ms
5,120 KB
testcase_06 AC 37 ms
5,552 KB
testcase_07 AC 33 ms
6,652 KB
testcase_08 AC 45 ms
6,700 KB
testcase_09 AC 45 ms
6,704 KB
testcase_10 AC 45 ms
6,652 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 25 ms
4,732 KB
testcase_15 AC 23 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 25 ms
5,652 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 37 ms
5,904 KB
testcase_20 AC 25 ms
4,852 KB
testcase_21 AC 15 ms
4,380 KB
testcase_22 AC 9 ms
4,376 KB
testcase_23 AC 35 ms
5,468 KB
testcase_24 AC 38 ms
5,908 KB
testcase_25 AC 22 ms
4,640 KB
testcase_26 AC 36 ms
5,800 KB
testcase_27 AC 30 ms
5,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

const MOD: i64 = 1_000_000_007;

fn calc(a: &[usize]) -> Vec<i64> {
    let n = a.len();
    let mut acc = vec![0; n + 1];
    for i in 0..n {
        acc[i + 1] = acc[i] ^ a[i];
    }
    let mut dp = vec![0i64; 1024];
    for &a in &acc {
        dp[a] += 1;
    }
    for i in 0..10 {
        for bits in 0..1024 {
            if (bits & 1 << i) == 0 {
                let x = dp[bits];
                let y = dp[bits | 1 << i];
                dp[bits] = x + y;
                dp[bits | 1 << i] = x - y;
            }
        }
    }
    for bits in 0..1024 {
        dp[bits] = dp[bits] * dp[bits];
    }
    for i in 0..10 {
        for bits in 0..1024 {
            if (bits & 1 << i) == 0 {
                let x = dp[bits];
                let y = dp[bits | 1 << i];
                dp[bits] = (x + y) / 2;
                dp[bits | 1 << i] = (x - y) / 2;
            }
        }
    }
    dp[0] -= (n + 1) as i64;
    for bits in 0..1024 {
        dp[bits] /= 2;
        dp[bits] %= MOD;
    }
    eprintln!("{:?}", &dp[..16]);
    dp
}

fn main() {
    input! {
        n: usize, m: usize, k: usize,
        a: [usize; n],
        b: [usize; m],
    }
    let c = calc(&a);
    let d = calc(&b);
    let mut ans = 0;
    for i in 0..1024 {
        ans = (ans + c[i] * d[k ^ i]) % MOD;
    }
    println!("{}", ans);
}
0