結果
問題 | No.1072 A Nice XOR Pair |
ユーザー | htensai |
提出日時 | 2020-06-10 08:44:39 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,212 ms / 2,000 ms |
コード長 | 844 bytes |
コンパイル時間 | 6,005 ms |
コンパイル使用メモリ | 79,664 KB |
実行使用メモリ | 78,584 KB |
最終ジャッジ日時 | 2023-09-03 20:31:48 |
合計ジャッジ時間 | 14,734 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 131 ms
55,688 KB |
testcase_01 | AC | 132 ms
55,784 KB |
testcase_02 | AC | 132 ms
55,560 KB |
testcase_03 | AC | 132 ms
55,796 KB |
testcase_04 | AC | 130 ms
55,700 KB |
testcase_05 | AC | 130 ms
55,640 KB |
testcase_06 | AC | 213 ms
58,284 KB |
testcase_07 | AC | 1,212 ms
78,584 KB |
testcase_08 | AC | 894 ms
64,940 KB |
testcase_09 | AC | 860 ms
64,736 KB |
testcase_10 | AC | 908 ms
62,980 KB |
testcase_11 | AC | 936 ms
68,936 KB |
testcase_12 | AC | 1,145 ms
76,024 KB |
ソースコード
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); } }