Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2023
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. /** _ _______
  2. | | |____ /
  3. | | / /
  4. | | / /
  5. | |____ / /
  6. |______| /_/
  7. **/
  8.  
  9. #include<bits/stdc++.h>
  10. using namespace std;
  11. void dbg_out(){
  12. cerr<<endl;
  13. }
  14. template <typename Head,typename... Tail>
  15. void dbg_out(Head H,Tail... T){
  16. cerr<<' '<<H;
  17. dbg_out(T...);
  18. }
  19. #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
  20. typedef long long ll;
  21. typedef long double ld;
  22. typedef vector<ll>vl;
  23. typedef deque<ll>dq;
  24. typedef pair<ll,ll>pl;
  25. #define yes {cout<<"YES"<<endl;return;}
  26. #define no {cout<<"NO"<<endl;return;}
  27. #define CR(_) {cout<<_<<endl;return;}
  28. #define F first
  29. #define S second
  30. #define pb push_back
  31. #define ppb pop_back
  32. #define pf push_front
  33. #define ppf pop_front
  34. #define aff(v) for(auto e:v) cout<<e<<" ";cout<<endl;
  35. #define all(v) v.begin(), v.end()
  36. #define rall(v) v.rbegin(), v.rend()
  37. //const ll MOD = LLONG_MAX;
  38. //const ll MOD = 998244353;
  39. const ll MOD=1000000007;
  40. const ld eps=1e-7;
  41. const double PI=acos(-1);
  42. const int N=2e5+5;
  43. const ll INF=1e18;
  44. const int L=log2(N)+1;
  45.  
  46. string to_bin(ll n){
  47. string ch="";
  48. while(n>0){
  49. char a=n%2+'0';
  50. ch=a+ch;
  51. n=n/2;
  52. }
  53. return ch;
  54. }
  55.  
  56. int to_dec(string ch){
  57. int res=0;
  58. for(int i=ch.size()-1;i>=0;i--){
  59. int a=ch[i]-'0';
  60. int p=ch.size()-i-1;
  61. if(a)res+=1<<p;
  62. }
  63. return res;
  64. }
  65.  
  66. void solve(){
  67. int n;cin>>n;
  68. int k;cin>>k;
  69. vector<int>v(n);
  70. for(int i=0;i<n;i++)cin>>v[i];
  71. string shit="";
  72. for(int i=0;i<k;i++){
  73. shit+='1';
  74. }
  75. for(int i=k;i<10;i++){
  76. shit+='0';
  77. }
  78. int ans=to_dec(shit);
  79. int op=0;
  80. vector<bool>vis(1024,0);
  81. vector<int>vect;vect.pb(0);
  82. vector<bool>done(1024);
  83. vis[0]=1;
  84. for(int i=0;i<n;i++){
  85. op=v[i]^op;
  86. if(vis[op])continue;
  87. for(auto j:vect){
  88. int cur=op^j;
  89. ans=max(ans,cur);
  90.  
  91. if(done[cur])continue;
  92. else done[cur]=1;
  93.  
  94. string bin=to_bin(cur);
  95. while(bin.size()<10)bin='0'+bin;
  96.  
  97. int alpha=k;
  98. for(int f=0;f<10;f++){
  99. if(alpha==0)break;
  100. if(bin[f]=='0'){
  101. bin[f]='2';alpha--;
  102. }
  103. }
  104. for(int f=9;f>=0;f--){
  105. if(alpha==0)break;
  106. if(bin[f]=='1'){
  107. bin[f]='0';alpha--;
  108. }
  109. }
  110. for(int f=0;f<10;f++)if(bin[f]=='2')bin[f]='1';
  111. ans=max(ans,to_dec(bin));
  112. }
  113. if(!vis[op]){
  114. vis[op]=1;
  115. vect.pb(op);
  116. }
  117. }
  118. cout<<ans<<endl;
  119. }
  120. int main(){
  121. ios_base::sync_with_stdio(false);cin.tie(0);
  122. int _=1;
  123. cin>>_;
  124. //cout<<fixed<<setprecision(6);
  125. while(_--)solve();
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement