結果

問題 No.1969 XOR Equation
ユーザー chineristACchineristAC
提出日時 2022-02-09 11:26:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,499 bytes
コンパイル時間 5,221 ms
コンパイル使用メモリ 225,936 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-21 01:34:24
合計ジャッジ時間 9,347 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 182 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    }


}
0