結果

問題 No.2672 Subset Xor Sum
コンテスト
ユーザー ks2m
提出日時 2024-03-15 22:00:29
言語 Java
(openjdk 26.0.2.1 + ACL)
コンパイル:
javac -J-Duser.language=en -encoding UTF8 -cp /opt/aclib/ac_library.jar _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true -cp .:/opt/aclib/ac_library.jar _class_
結果
AC  
実行時間 248 ms / 2,000 ms
+ 633µs
コード長 1,128 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,105 ms
コンパイル使用メモリ 84,900 KB
実行使用メモリ 87,928 KB
最終ジャッジ日時 2026-09-06 12:05:42
合計ジャッジ時間 10,602 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 66
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		int m = 5000;
		int[] c = new int[m + 1];
		int xor = 0;
		for (int i = 0; i < n; i++) {
			xor ^= a[i];
			c[a[i]]++;
		}
		if (xor != 0) {
			System.out.println("No");
			return;
		}

		if (n > 2) {
			for (int i = 0; i < c.length; i++) {
				if (c[i] >= 2) {
					System.out.println("Yes");
					return;
				}
			}
		}

		boolean[] dp = new boolean[8200];
		dp[0] = true;
		for (int i = 0; i < n - 1; i++) {
			boolean[] wk = Arrays.copyOf(dp, dp.length);
			wk[0] = false;
			for (int j = 0; j < dp.length; j++) {
				if (dp[j]) {
					wk[j ^ a[i]] = true;
				}
			}
			if (wk[0]) {
				System.out.println("Yes");
				return;
			}
			dp = wk;
		}
		System.out.println("No");
	}
}
0