結果
| 問題 |
No.2844 Birthday Party Decoration
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-08-23 21:24:59 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
AC
|
| 実行時間 | 100 ms / 2,000 ms |
| コード長 | 1,927 bytes |
| コンパイル時間 | 8,077 ms |
| コンパイル使用メモリ | 168,392 KB |
| 実行使用メモリ | 194,016 KB |
| 最終ジャッジ日時 | 2024-08-23 21:25:20 |
| 合計ジャッジ時間 | 9,117 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 4 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (99 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
static int NN => int.Parse(ReadLine());
static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
public static void Main()
{
Solve();
}
static void Solve()
{
var t = NN;
var ans = new long[t];
for (var u = 0; u < t; ++u)
{
var p = ReadLine().Split();
var (n, x) = (int.Parse(p[0]), long.Parse(p[1]));
var c = NList;
ans[u] = Shop(n, x, c);
}
WriteLine(string.Join("\n", ans));
}
static long Shop(int n, long x, int[] c)
{
var list = new List<(long l, long r)>();
var max = x;
for (var i = 0; i < n; ++i)
{
var lx = x;
if (((lx >> c[i]) & 1) == 0)
{
for (var j = 0; j < c[i]; ++j) if (((lx >> j) & 1) != 0) lx ^= 1L << j;
--lx;
}
var rx = x;
if (((rx >> c[i]) & 1) == 0)
{
rx ^= 1L << c[i];
for (var j = 0; j < c[i]; ++j) if (((rx >> j) & 1) != 0) rx ^= 1L << j;
}
if (lx >= 0 && lx != rx) list.Add((lx, rx));
else max = Math.Max(max, rx);
}
if (list.Count == 0) return (max - x) * 2;
list.Sort((l, r) => r.l.CompareTo(l.l));
var ans = (max - list[^1].l) * 2;
while (list.Count > 0)
{
max = Math.Max(max, list[^1].r);
list.RemoveAt(list.Count - 1);
if (list.Count > 0) ans = Math.Min(ans, (max - list[^1].l) * 2);
else ans = Math.Min(ans, (max - x) * 2);
}
return ans;
}
}