結果

問題 No.3780 Erase and Mex
コンテスト
ユーザー tobisatis
提出日時 2026-10-30 22:08:08
言語 C#
(.NET 10.0.402 + ACL)
コンパイル:
dotnet_c
実行:
/usr/bin/dotnet_wrap
結果
WA  
実行時間 -
コード長 984 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 9,347 ms
コンパイル使用メモリ 173,052 KB
実行使用メモリ 65,484 KB
最終ジャッジ日時 2026-10-30 22:08:25
合計ジャッジ時間 15,286 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 29 WA * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (258 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net10.0/main.dll
  main -> /home/judge/data/code/bin/Release/net10.0/publish/

ソースコード

diff #
raw source code

#nullable enable

const long Max = long.MaxValue;

static int Solve()
{
    var n = int.Parse(Console.ReadLine()!);
    var az = Console.ReadLine()!.Split(' ').Select(int.Parse).ToArray();

    bool J(int k)
    {
        var cz = new int[k];
        foreach (var a in az)
        {
            if (a < k) cz[a]++;
            else cz[0]++;
        }
        var d = 0L;
        for (var i = k - 1; i >= 0; i--)
        {
            var c = cz[i];
            if (c > d) cz[0] += c - (int)d - 1;
            else if (d >= Max - d + c - 1) d = Max;
            else d += d - c + 1;
        }
        return cz[0] > d;
    }

    var pass = 0;
    var fail = n + 2;
    while (fail - pass >= 2)
    {
        var mid = (pass + fail) >> 1;
        if (J(mid)) pass = mid;
        else fail = mid;
    }
    return pass;
}

var t = int.Parse(Console.ReadLine()!);
var ans = Enumerable.Range(0, t).Select(_ => Solve()).ToArray();
Console.WriteLine(string.Join(Environment.NewLine, ans));
0