結果
問題 |
No.1072 A Nice XOR Pair
|
ユーザー |
|
提出日時 | 2022-01-23 12:34:42 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 29 ms / 2,000 ms |
コード長 | 1,128 bytes |
コンパイル時間 | 24,166 ms |
コンパイル使用メモリ | 379,680 KB |
実行使用メモリ | 12,064 KB |
最終ジャッジ日時 | 2024-11-29 11:13:15 |
合計ジャッジ時間 | 13,786 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 11 |
ソースコード
#[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); } } 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; } count / 2 })(); println!("{}", ans); }