結果
| 問題 |
No.2844 Birthday Party Decoration
|
| コンテスト | |
| ユーザー |
yamada
|
| 提出日時 | 2024-08-23 21:57:41 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 14 ms / 2,000 ms |
| コード長 | 2,683 bytes |
| コンパイル時間 | 3,045 ms |
| コンパイル使用メモリ | 164,768 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-08-23 21:57:45 |
| 合計ジャッジ時間 | 3,521 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 4 |
ソースコード
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <stack>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <bitset>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>=b;--i)
#define fore(i, a) for(auto& i : a)
#define pi 3.141592653589793238
typedef long long ll;
typedef pair<ll,ll> pp;
typedef vector<ll> vl;
typedef vector<ulong> vu;
typedef vector<vl> vvl;
typedef vector<pp> vp;
typedef vector<vp> vvp;
typedef priority_queue<pp, vp, greater<pp> > pq;
vl kaijou;
void kaijou_set(ll m) {kaijou.push_back(1); rep(i, 1, 1000009)kaijou.push_back((kaijou[i-1] * i) % m); return;}
ll C(ll a, ll b, ll m) {if(a < b) return 0; return (kaijou[a] * pow_mod(kaijou[a-b] * kaijou[b], m-2, m)) % m;}
template <typename T, typename F>
T bisect(T ok, T bad, F pred) {while (bad - ok > 1) {T mid = ok + (bad - ok) / 2; (pred(mid) ? ok : bad) = mid;} return bad;}
bool chmin(ll &a, ll b) {if (a > b) {a = b;return true;} return false;}
bool chmax(ll &a, ll b) {if (a < b) {a = b;return true;} return false;}
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
ll gcd(ll x, ll y) {if(y == 0)return x; return gcd(y, x % y); }
ll RU(ll a, ll b) {return a / b + (a % b && (a ^ b) >= 0); }
ll mod=998244353; ll mof=1000000007;
ll hukugen(bitset<60>b){
ll ans=0;
rep(i,0,60){
if(b[i])ans+=1LL<<i;
}
return ans;
}
int main()
{
ll t;cin>>t;
rep(xxx,0,t){
ll n,x,c[69];
cin>>n>>x;
bitset<60>bs(x);
pp lr[69];//iを買える店で一番家から近い店
rep(i,1,n+1){
cin>>c[i];
if(bs[c[i]])lr[i]=make_pair(0,0);
else{
bitset<60>l(x),r(x);
rep(j,0,c[i]){
l.reset(j);
r.reset(j);
}
r.set(c[i]);
//cout<<xxx<<" "<<i<<" "<<l<<" "<<r<<endl;
if(l==0)lr[i]=make_pair((ll)-2e18,hukugen(r));
else lr[i]=make_pair(hukugen(l)-1,hukugen(r));
}
//cout<<xxx<<" "<<i<<" "<<lr[i].first<<" "<<lr[i].second<<endl;
}
sort(lr+1,lr+n+1);
lr[n+1]=make_pair(x,x);
ll l=lr[1].first,r=x;
ll ans=(r-l)*2;
rep(i,1,n+1){
//i番目の店を右側に移すことを考える
l=lr[i+1].first;
chmax(r,lr[i].second);
chmin(ans,(r-l)*2);
}
cout<<ans<<endl;
}
}
yamada