結果
| 問題 |
No.1969 XOR Equation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-02-09 11:26:13 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,499 bytes |
| コンパイル時間 | 20,960 ms |
| コンパイル使用メモリ | 254,156 KB |
| 最終ジャッジ日時 | 2025-01-27 20:50:20 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 23 TLE * 13 |
ソースコード
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <random>
#include <stdio.h>
#include <fstream>
#include <functional>
#include <cassert>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n,c) for (int i=0;i<n;i+=c)
#define append push_back
#define all(x) (x).begin(), (x).end()
template<class T>
using vec = vector<T>;
template<class T>
using vvec = vec<vec<T>>;
template<class T>
using vvvec = vec<vvec<T>>;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<class T>
bool chmin(T &a, T b){
if (a>b){
a = b;
return true;
}
return false;
}
template<class T>
bool chmax(T &a, T b){
if (a<b){
a = b;
return true;
}
return false;
}
template<class T>
T sum(vec<T> x){
T res=0;
for (auto e:x){
res += e;
}
return res;
}
template<class T>
void printv(vec<T> x){
for (auto e:x){
cout<<e<<" ";
}
cout<<"\n";
}
ll ans = (1ll)<<61;
ll A[10000];
int N;
ll Y;
ll dfs(int d,ll tmp,set<ll> up){
//cout<<d<<" "<<tmp<<" "<<ans<<endl;
//rep(i,N,1){
//cout<<agari[i]<<" ";
//}
//cout<<endl;
if (d==61){
if ((up.size()&1)==0){
return tmp;
}
else{
return ans;
}
}
ll res = ans;
if (tmp > ans){
return ans;
}
set<ll> one,two;
rep(i,N,1){
if ((A[i]>>d) & 1){
if(up.find(i)!=up.end()){
two.insert(i);
}
else{
one.insert(i);
}
}
else{
if (up.find(i)!=up.end()){
one.insert(i);
}
}
}
if ((one.size()&1)==((Y>>d)&1)){
res = min(res,dfs(d+1,tmp,two));
}
if (((N-one.size())&1)==((Y>>d)&1)){
for (auto i:one){
two.insert(i);
}
res = min(res,dfs(d+1,tmp+((1ll)<<d),two));
}
ans = min(ans,res);
return res;
}
ll solve_brute(int n,ll y,vec<ll> a){
N = n;
Y = y;
rep(i,n,1){
A[i] = a[i];
}
ans = (1ll)<<61;
set<ll> S = {};
ll res = dfs(0,0,S);
if (res < ((1ll)<<61)){
return res;
}
return -1;
}
int main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
cin>>T;
while (T--){
int n;
cin>>n;
ll y;
cin>>y;
vec<ll> a(n);
rep(i,n,1){
cin>>a[i];
}
cout<<solve_brute(n,y,a)<<endl;
}
}