結果

問題 No.2648 [Cherry 6th Tune D] 一次元の馬
ユーザー tobisatis
提出日時 2024-02-23 21:57:39
言語 C#
(.NET 8.0.404)
結果
AC  
実行時間 270 ms / 2,000 ms
コード長 2,455 bytes
コンパイル時間 10,073 ms
コンパイル使用メモリ 168,884 KB
実行使用メモリ 191,600 KB
最終ジャッジ日時 2025-06-20 02:03:32
合計ジャッジ時間 17,686 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (114 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

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 t = Int();
        var ans = new List<long>();
        for (var i = 0; i < t; i++)
        {
            ans.Add(Solve2());
        }
        Out(ans);
        return null;
    }

    long Solve2()
    {
        var n = Int();
        var az = n.Repeat(Int);
        bool F(int x)
        {
            var bz = new long[n];
            long lx = x;
            for (var i = 0; i < n; i++)
            {
                bz[i] = lx * (i + 1) + az[i];
            }
            for (var i = 1; i < n; i++)
            {
                if (bz[i] <= bz[i - 1]) return false;
            }
            return true;
        }
        int BinarySearch(int pass, int fail)
        {
            while (Math.Abs(pass - fail) > 1)
            {
                var middle = (pass + fail) >> 1;
                if (F(middle)) pass = middle; else fail = middle;
            }
            return pass;
        }
        var res = BinarySearch(int.MaxValue / 2 - 2, -1);
        return res;
    }

    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 };

    #pragma warning disable IDE0051
    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();
    }
    #pragma warning restore IDE0051
}
0