結果
| 問題 |
No.2844 Birthday Party Decoration
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-08-24 17:00:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,173 bytes |
| コンパイル時間 | 344 ms |
| コンパイル使用メモリ | 45,952 KB |
| 最終ジャッジ日時 | 2025-02-24 00:39:34 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 4 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:34:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
34 | scanf("%d", &tn);
| ~~~~~^~~~~~~~~~~
main.cpp:39:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
39 | scanf("%d%lld", &n, &x);
| ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:40:38: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
40 | for (int i = 0; i < n; i++) scanf("%d", cs + i);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 2844.cc: No.2844 Birthday Party Decoration - yukicoder
*/
#include<cstdio>
#include<algorithm>
#include<utility>
using namespace std;
/* constant */
const int MAX_N = 60;
const int BN = 60;
const long long LINF = 1LL << (BN + 1);
/* typedef */
using ll = long long;
using pll = pair<ll,ll>;
/* global variables */
int cs[MAX_N];
pll ps[MAX_N + 1];
/* subroutines */
/* main */
int main() {
int tn;
scanf("%d", &tn);
while (tn--) {
int n;
ll x;
scanf("%d%lld", &n, &x);
for (int i = 0; i < n; i++) scanf("%d", cs + i);
ll r = x;
int m = 0;
for (int i = 0; i < n; i++) {
ll bi = (1LL << cs[i]);
if ((x & bi) == 0) {
ll li = (x & ~(bi - 1)) - 1;
ll ri = (x & ~(bi - 1)) | bi;
if (li < 0) r = max(r, ri);
else ps[m++] = {li, ri};
}
}
ll mind = LINF;
if (m > 0) {
sort(ps, ps + m);
ps[m] = {x, x};
ll l = ps[0].first;
mind = r - l;
for (int i = 0; i < m; i++) {
r = max(r, ps[i].second);
l = ps[i + 1].first;
mind = min(mind, r - l);
}
}
else
mind = r - x;
printf("%lld\n", mind * 2);
}
return 0;
}
tnakao0123