結果
問題 | No.1072 A Nice XOR Pair |
ユーザー |
![]() |
提出日時 | 2020-06-10 08:44:39 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,137 ms / 2,000 ms |
コード長 | 844 bytes |
コンパイル時間 | 2,491 ms |
コンパイル使用メモリ | 85,676 KB |
実行使用メモリ | 84,640 KB |
最終ジャッジ日時 | 2024-06-13 01:19:13 |
合計ジャッジ時間 | 11,185 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 11 |
ソースコード
import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int x = sc.nextInt(); HashMap<Integer, Integer> map = new HashMap<>(); for (int i = 0; i < n; i++) { int y = sc.nextInt(); if (map.containsKey(y)) { map.put(y, map.get(y) + 1); } else { map.put(y, 1); } } long total = 0; if (x == 0) { for (int y : map.values()) { total += (long)(y - 1) * y / 2; } } else { for (Map.Entry<Integer, Integer> entry : map.entrySet()) { int key = entry.getKey() ^ x; int value = entry.getValue(); if (map.containsKey(key)) { total += (long)value * map.get(key); } } total /= 2; } System.out.println(total); } }