結果

問題 No.2844 Birthday Party Decoration
ユーザー MMMM
提出日時 2024-08-23 22:38:11
言語 C++23(gcc13)
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,824 bytes
コンパイル時間 6,022 ms
コンパイル使用メモリ 337,956 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-08-23 22:38:21
合計ジャッジ時間 6,513 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 = 3e18;
      }
    }
    
    // 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 = 1e18, 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;
  }
}
0