結果

問題 No.1072 A Nice XOR Pair
ユーザー phsplsphspls
提出日時 2020-06-24 23:04:20
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 944 bytes
コンパイル時間 945 ms
コンパイル使用メモリ 157,752 KB
実行使用メモリ 8,600 KB
最終ジャッジ日時 2023-09-16 21:25:30
合計ジャッジ時間 1,932 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 48 ms
8,396 KB
testcase_08 AC 22 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 35 ms
5,368 KB
testcase_12 AC 44 ms
8,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::HashMap;

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

    let mut mapping: HashMap<usize, usize> = HashMap::new();
    for _ in 0..n {
        let mut a = String::new();
        std::io::stdin().read_line(&mut a).ok();
        let a: usize = a.trim().parse().unwrap();
        if let Some(b) = mapping.get_mut(&a) {
            *b += 1;
        } else {
            mapping.insert(a, 1);
        }
    }
    let mut result: usize = 0;
    mapping.iter().for_each(|pair| {
        let b = pair.0 ^ x;
        if x != 2 {
            result += pair.1 * mapping.get(&b).unwrap_or(&0usize);
        } else {
            result += pair.1 * (pair.1 - 1);
        }
    });
    if x != 0 {
      result /= 2;
    }
    println!("{}", result);
}
0