結果
| 問題 |
No.2844 Birthday Party Decoration
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2024-08-24 01:25:46 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 18 ms / 2,000 ms |
| コード長 | 1,409 bytes |
| コンパイル時間 | 1,866 ms |
| コンパイル使用メモリ | 206,720 KB |
| 最終ジャッジ日時 | 2025-02-24 00:32:49 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 4 |
ソースコード
#include <bits/stdc++.h>
#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
using ll = std::int64_t;
using P = std::tuple<ll, ll>;
int main(){
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int T;
std::cin >> T;
for(int _=0;_<T;_++){
int N;
ll X;
std::cin >> N >> X;
std::vector<ll> c(N);
for(int i=0;i<N;i++){
std::cin >> c[i];
}
std::vector<P> p;
for(int i=0;i<N;i++){
if(X >> c[i] & 1){
p.emplace_back(X, i);
continue;
}
if(X >= (1ll << c[i])){
p.emplace_back((X & ~((1ll << c[i]) - 1)) - 1, i);
}
p.emplace_back((X & ~((1ll << c[i]) - 1)) | (1ll << c[i]), i);
}
std::sort(std::begin(p), std::end(p));
ll res = std::numeric_limits<ll>::max();
for(int i=0;i+N<=p.size();i++){
int last = -1;
ll set = 0;
for(int j=i;j<p.size();j++){
set |= 1ll << snd(p[j]);
if(set == (1ll << N) - 1){
last = j;
break;
}
}
if(last != -1){
res = std::min<ll>(res, 2ll * (std::max(fst(p[last]), X) - std::min(fst(p[i]), X)));
}
}
std::cout << res << std::endl;
}
}
tottoripaper