結果
| 問題 |
No.2799 Cut and Eat
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-06-28 23:19:28 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,544 bytes |
| コンパイル時間 | 11,677 ms |
| コンパイル使用メモリ | 167,140 KB |
| 実行使用メモリ | 188,096 KB |
| 最終ジャッジ日時 | 2024-06-28 23:19:49 |
| 合計ジャッジ時間 | 10,644 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 27 WA * 4 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (96 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/
ソースコード
namespace AtCoder;
#nullable enable
using System.Numerics;
static class Extensions
{
public static T[] Repeat<T>(this int time, Func<T> F) => Enumerable.Range(0, time).Select(_ => F()).ToArray();
}
class AtCoder
{
object? Solve()
{
var n = Int();
var k = Int();
var az = new List<(int, int, int)>();
(int[], int) F(int x, int t)
{
var res = new int[2];
if (x <= k)
{
res[t] += x;
return (res, t ^ 1);
}
var x0 = (x + 1) / 2;
var x1 = x - x0;
var (m0, t0) = F(x0, t ^ 1);
res[0] += m0[0];
res[1] += m0[1];
if (x1 <= k)
{
res[t0] += x1;
return (res, t0 ^ 1);
}
var (m1, t1) = F(x1, t0 ^ 1);
res[0] += m1[0];
res[1] += m1[1];
return (res, t1);
}
for (var i = 0; i < n; i++)
{
var a = Int();
var (m, t) = F(a, 0);
var m0 = m[0];
var m1 = m[1];
az.Add((m1 - m0, m0, m1));
}
az.Sort();
var ans = 0L;
var ta = 0;
foreach (var (_, v0, v1) in az)
{
if (ta == 0) ans += v0;
else ans += v1;
ta ^= 1;
}
return ans;
}
public static void Main() => new AtCoder().Run();
public void Run()
{
var res = Solve();
if (res != null)
{
if (res is bool yes) res = yes ? "Yes" : "No";
sw.WriteLine(res);
}
sw.Flush();
}
string[] input = Array.Empty<string>();
int iter = 0;
readonly StreamWriter sw = new(Console.OpenStandardOutput()) { AutoFlush = false };
string String()
{
while (iter >= input.Length) (input, iter) = (Console.ReadLine()!.Split(' '), 0);
return input[iter++];
}
T Input<T>() where T : IParsable<T> => T.Parse(String(), null);
int Int() => Input<int>();
void Out(object? x, string? separator = null)
{
separator ??= Environment.NewLine;
if (x is System.Collections.IEnumerable obj and not string)
{
var firstLine = true;
foreach (var item in obj)
{
if (!firstLine) sw.Write(separator);
firstLine = false;
sw.Write(item);
}
}
else sw.Write(x);
sw.WriteLine();
}
}