結果

問題 No.2672 Subset Xor Sum
ユーザー Aeren
提出日時 2024-03-15 21:31:23
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 916 bytes
コンパイル時間 2,447 ms
コンパイル使用メモリ 248,216 KB
実行使用メモリ 7,040 KB
最終ジャッジ日時 2024-09-30 04:14:13
合計ジャッジ時間 4,482 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 66
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
// #include <x86intrin.h>
using namespace std;
#if __cplusplus >= 202002L
using namespace numbers;
#endif



int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(ios::badbit | ios::failbit);
	int n;
	cin >> n;
	vector<int> a(n);
	copy_n(istream_iterator<int>(cin), n, a.begin());
	if(accumulate(a.begin(), a.end(), 0, bit_xor<>()) != 0){
		cout << "No\n";
		return 0;
	}
	vector<int> pref(n), found(10001);
	found[0] = true;
	for(auto i = 0; i < n - 1; ++ i){
		pref[i + 1] = pref[i] ^ a[i];
		if(found[pref[i + 1]]){
			cout << "Yes\n";
			return 0;
		}
		found[pref[i + 1]] = true;
	}
	vector<int> dp(10001);
	for(auto i = 0; i < n - 1; ++ i){
		for(auto x = 0; x <= 10000; ++ x){
			if(dp[x]){
				dp[x ^ a[i]] = true;
			}
		}
		dp[a[i]] = true;
		if(dp[0]){
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
	return 0;
}

/*

*/
0