結果

問題 No.1072 A Nice XOR Pair
ユーザー tenten
提出日時 2020-08-20 06:40:53
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,032 ms / 2,000 ms
コード長 633 bytes
コンパイル時間 2,821 ms
コンパイル使用メモリ 74,968 KB
実行使用メモリ 68,544 KB
最終ジャッジ日時 2024-10-12 21:41:23
合計ジャッジ時間 9,977 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

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