結果

問題 No.1072 A Nice XOR Pair
ユーザー tentententen
提出日時 2020-08-20 06:40:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,155 ms / 2,000 ms
コード長 633 bytes
コンパイル時間 2,230 ms
コンパイル使用メモリ 76,292 KB
実行使用メモリ 68,268 KB
最終ジャッジ日時 2024-04-20 23:20:28
合計ジャッジ時間 10,712 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
41,196 KB
testcase_01 AC 134 ms
41,412 KB
testcase_02 AC 132 ms
41,696 KB
testcase_03 AC 135 ms
41,656 KB
testcase_04 AC 134 ms
41,424 KB
testcase_05 AC 137 ms
41,440 KB
testcase_06 AC 215 ms
43,580 KB
testcase_07 AC 1,155 ms
68,268 KB
testcase_08 AC 990 ms
57,776 KB
testcase_09 AC 929 ms
57,988 KB
testcase_10 AC 1,011 ms
58,008 KB
testcase_11 AC 1,037 ms
63,092 KB
testcase_12 AC 1,059 ms
67,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		long total = 0;
		HashMap<Integer, Integer> map = new HashMap<>();
		for (int i = n - 1; i >= 0; i--) {
		    if (map.containsKey(arr[i] ^ x)) {
		        total += map.get(arr[i] ^ x);
		    }
		    if (map.containsKey(arr[i])) {
		        map.put(arr[i], map.get(arr[i]) + 1);
		    } else {
		        map.put(arr[i], 1);
		    }
		}
		System.out.println(total);
	}
}
0