結果

問題 No.1072 A Nice XOR Pair
ユーザー Masaki KitaguchiMasaki Kitaguchi
提出日時 2022-01-23 12:51:31
言語 Rust
(1.72.1)
結果
WA  
実行時間 -
コード長 1,151 bytes
コンパイル時間 3,473 ms
コンパイル使用メモリ 155,064 KB
実行使用メモリ 12,112 KB
最終ジャッジ日時 2023-08-19 17:22:59
合計ジャッジ時間 3,537 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 37 ms
12,112 KB
testcase_08 AC 19 ms
5,508 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 28 ms
8,920 KB
testcase_12 AC 34 ms
12,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[macro_export]
macro_rules! setup {
    { mut $input:ident: SplitWhitespace $(,)? } => {
        use std::io::Read;
        let mut buf = String::new();
        std::io::stdin().read_to_string(&mut buf).ok();
        let mut $input = buf.split_whitespace();
    };
}

#[macro_export]
macro_rules! parse_next {
    ($str_iter:expr) => {
        $str_iter.next().unwrap().parse().ok().unwrap()
    };
}

fn main() {
    setup! { mut input: SplitWhitespace };

    let n: usize = parse_next!(input);
    let x: usize = parse_next!(input);
    let a: Vec<usize> = (0..n).map(|_| parse_next!(input)).collect();

    let mut c = std::collections::HashMap::new();
    for i in 0..n {
        let key = x ^ a[i];
        if let Some(value) = c.get_mut(&key) {
            *value += 1;
        } else {
            c.insert(key, 1 as u64);
        }
    }

    let ans = (|| {
        let mut count = 0;
        for i in 0..n {
            if let Some(value) = c.get(&a[i]) {
                count += *value;
            }
        }
        // if x == 0 {
        //     count -= n as u64;
        // }
        count / 2
    })();

    println!("{}", ans);
}
0