結果
| 問題 | 
                            No.2844 Birthday Party Decoration
                             | 
                    
| コンテスト | |
| ユーザー | 
                             MM
                         | 
                    
| 提出日時 | 2024-08-23 22:39:10 | 
| 言語 | C++23  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,824 bytes | 
| コンパイル時間 | 6,192 ms | 
| コンパイル使用メモリ | 338,368 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-08-23 22:39:17 | 
| 合計ジャッジ時間 | 6,675 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | WA * 4 | 
ソースコード
#include<bits/stdc++.h>
#include<atcoder/all>
#define chmin(x,y) (x) = min((x),(y))
#define chmax(x,y) (x) = max((x),(y))
using namespace std;
using namespace atcoder;
using ll = long long;
const ll mod = 998244353;
using mint = modint998244353;
using Graph = vector<vector<int>>;
const vector<int> dx ={1,0,-1,0}, dy = {0,1,0,-1};
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int main() {
  // input
  const int M = 60;
  int t; cin >> t;
  while(t--){
    // input
    int N; ll X;
    cin >> N >> X;
    vector<int> C(N),B(M);
    for(int i = 0; i < N; i++){
      cin >> C[i];
      B[C[i]] = 1;
    }
    // solve
    vector<pair<ll,int>> L(N),R(N);
    for(int i = 0; i < N; i++){
      if(X & (1LL<<C[i])){
        L[i] = {0,i}; R[i] = {0,i};
      }
      else{
        ll shift = (X >> C[i]) << C[i];
        ll r = (shift | 1LL<<C[i]), l = shift - 1;
        L[i] = {abs(l-X),i}, R[i] = {abs(r-X),i};
        if(l == -1) L[i].first = 9e18;
      }
    }
    
    // debug
    for(int i = 0; i < N; i++){
      // cout << i << " " << C[i] << " " << L[i].first << " " << R[i].first << endl;
    }
    
    // solve
    sort(R.begin(),R.end());
    sort(L.begin(),L.end());
    reverse(L.begin(),L.end());
    ll ans = 9e18, tmp_b = 0, tmp_d = 0;
    
    for(int i = 0; i < N; i++){
      chmax(tmp_d,R[i].first);
      tmp_b |= (1LL<<R[i].second);
      
      ll tmp_l = 0, lft = 0;
      for(int j = 0; j < N; j++){
        if(__builtin_popcount(tmp_b | lft) == N) break;
        
        chmax(tmp_l,L[j].first);
        lft |= (1LL<<L[j].second);
      }
      
      if(tmp_l >= 0)
        chmin(ans,tmp_d+tmp_l);
    }
    
    // output
    cout << ans * 2 << endl;
  }
}
            
            
            
        
            
MM