結果
問題 | No.2844 Birthday Party Decoration |
ユーザー |
|
提出日時 | 2024-08-23 21:27:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 11 ms / 2,000 ms |
コード長 | 1,520 bytes |
コンパイル時間 | 2,245 ms |
コンパイル使用メモリ | 207,936 KB |
最終ジャッジ日時 | 2025-02-23 23:31:56 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 4 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; long long inf = 1LL<<61; while(T--){ long long N,X; cin >> N >> X; vector<int> C(N); for(auto &c : C) cin >> c; vector<pair<long long,int>> left(N),right(N); for(int i=0; i<N; i++){ int c = C.at(i); left.at(i).second = i; right.at(i).second = i; if(X&(1LL<<c)) continue; long long x = X%(1LL<<c); if(x == X) left.at(i) = {inf,i}; else left.at(i) = {x+1,i}; right.at(i) = {(1LL<<c)-x,i}; } sort(left.rbegin(),left.rend()); sort(right.rbegin(),right.rend()); long long answer = inf; for(int i=0; i<=N; i++){ vector<bool> need(N); for(int k=0; k<i; k++){ auto &[d,p] = left.at(k); need.at(p) = true; } bool ng = false; long long now = 0; for(int k=i; k<N; k++){ auto &[d,p] = left.at(k); if(d == inf) ng = true; now = d*2; break; } if(ng) continue; for(int k=0; k<N; k++){ auto &[d,p] = right.at(k); if(need.at(p)){ now += d*2; break; } } answer = min(answer,now); } cout << answer << "\n"; } }