結果
| 問題 |
No.1072 A Nice XOR Pair
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-24 23:07:23 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 49 ms / 2,000 ms |
| コード長 | 948 bytes |
| コンパイル時間 | 12,819 ms |
| コンパイル使用メモリ | 405,092 KB |
| 実行使用メモリ | 8,460 KB |
| 最終ジャッジ日時 | 2024-07-03 20:25:56 |
| 合計ジャッジ時間 | 13,333 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 11 |
ソースコード
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 != 0 {
result += pair.1 * mapping.get(&b).unwrap_or(&0usize);
} else {
result += pair.1 * (pair.1 - 1) / 2;
}
});
if x != 0 {
result /= 2;
}
println!("{}", result);
}