結果
| 問題 |
No.2844 Birthday Party Decoration
|
| コンテスト | |
| ユーザー |
ripity
|
| 提出日時 | 2024-08-23 22:08:44 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 26 ms / 2,000 ms |
| コード長 | 1,018 bytes |
| コンパイル時間 | 2,009 ms |
| コンパイル使用メモリ | 204,168 KB |
| 最終ジャッジ日時 | 2025-02-23 23:49:31 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 4 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
void solve() {
int N;
long long X;
cin >> N >> X;
unordered_map<long long, long long> dp, ep;
dp[0] = 0;
for(int i = 0; i < N; i++) {
int c;
cin >> c;
long long x = X & ((1LL << c) - 1);
long long y = X & (1LL << c);
if(y != 0) continue;
// cout << "#" << endl;
for(const auto [l, r] : dp) {
long long l2 = - 1 - x;
long long r2 = (1LL << c) - x;
// cout << l << " " << r << " * " << l2 << " " << r2 << endl;
{
if(!ep.count(l)) ep[l] = max(r, r2);
ep[l] = min(ep[l], max(r, r2));
}
if(X >= (1LL << c)) {
if(!ep.count(min(l, l2))) ep[min(l, l2)] = r;
ep[min(l, l2)] = min(ep[min(l, l2)], r);
}
}
swap(dp, ep);
ep.clear();
}
long long ans = 3LL << 60;
for(const auto &[l, r] : dp) {
ans = min(ans, 2 * (r - l));
// cout << l << " " << r << endl;
}
cout << ans << "\n";
}
int main() {
int T;
cin >> T;
while(T--) solve();
}
ripity