結果

問題 No.1072 A Nice XOR Pair
ユーザー ks2mks2m
提出日時 2020-06-05 21:53:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,008 ms / 2,000 ms
コード長 658 bytes
コンパイル時間 3,077 ms
コンパイル使用メモリ 73,652 KB
実行使用メモリ 75,332 KB
最終ジャッジ日時 2023-08-22 15:13:02
合計ジャッジ時間 9,388 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
56,084 KB
testcase_01 AC 120 ms
54,208 KB
testcase_02 AC 121 ms
56,260 KB
testcase_03 AC 121 ms
55,876 KB
testcase_04 AC 120 ms
55,968 KB
testcase_05 AC 122 ms
56,080 KB
testcase_06 AC 203 ms
58,564 KB
testcase_07 AC 1,008 ms
75,332 KB
testcase_08 AC 915 ms
65,220 KB
testcase_09 AC 836 ms
64,660 KB
testcase_10 AC 875 ms
65,256 KB
testcase_11 AC 837 ms
68,800 KB
testcase_12 AC 900 ms
73,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		long ans = 0;
		Map<Integer, Integer> map = new HashMap<>();
		for (int i = 0; i < n; i++) {
			int b = x ^ a[i];
			if (map.containsKey(b)) {
				ans += map.get(b);
			}
			if (map.containsKey(a[i])) {
				map.put(a[i], map.get(a[i]) + 1);
			} else {
				map.put(a[i], 1);
			}
		}
		System.out.println(ans);
	}
}
0