結果

問題 No.2693 Sword
ユーザー tobisatistobisatis
提出日時 2024-03-22 21:55:50
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 2,224 bytes
コンパイル時間 7,633 ms
コンパイル使用メモリ 156,864 KB
実行使用メモリ 182,684 KB
最終ジャッジ日時 2024-03-22 21:56:01
合計ジャッジ時間 10,947 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
31,140 KB
testcase_01 AC 60 ms
31,140 KB
testcase_02 AC 61 ms
31,140 KB
testcase_03 AC 60 ms
31,140 KB
testcase_04 AC 59 ms
31,140 KB
testcase_05 AC 59 ms
31,140 KB
testcase_06 AC 60 ms
31,140 KB
testcase_07 AC 59 ms
31,140 KB
testcase_08 AC 70 ms
31,140 KB
testcase_09 AC 65 ms
33,956 KB
testcase_10 AC 62 ms
31,908 KB
testcase_11 AC 62 ms
32,548 KB
testcase_12 AC 59 ms
31,140 KB
testcase_13 AC 63 ms
32,164 KB
testcase_14 AC 60 ms
31,268 KB
testcase_15 AC 65 ms
33,444 KB
testcase_16 AC 67 ms
34,852 KB
testcase_17 AC 68 ms
35,236 KB
testcase_18 AC 65 ms
33,060 KB
testcase_19 AC 64 ms
32,804 KB
testcase_20 AC 66 ms
34,340 KB
testcase_21 AC 67 ms
35,364 KB
testcase_22 AC 82 ms
33,316 KB
testcase_23 AC 64 ms
32,932 KB
testcase_24 AC 59 ms
31,140 KB
testcase_25 AC 59 ms
31,140 KB
testcase_26 AC 59 ms
31,140 KB
testcase_27 AC 59 ms
31,140 KB
testcase_28 AC 59 ms
31,140 KB
testcase_29 AC 60 ms
31,140 KB
testcase_30 AC 60 ms
31,140 KB
testcase_31 AC 60 ms
31,140 KB
testcase_32 AC 72 ms
182,684 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (106 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.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 n = Int();
        var p = Input<long>();
        var k = Int();
        var max = 1L;
        for (var i = 1; i <= 18; i++) max *= 10;
        max++;
        var min = long.MinValue / 4;
        var dp = new long[1];
        dp[0] = p;
        for (var i = 1; i <= n; i++)
        {
            var t = Int();
            var b = Int();
            var ep = new long[i + 1];
            for (var j = 0; j < i; j++) ep[j] = dp[j];
            ep[i] = min;
            for (var j = i - 1; j >= 0; j--) ep[j + 1] = Math.Max(ep[j + 1], t == 1 ? ep[j] + b : ep[j] * 2);
            for (var j = 0; j <= i; j++) ep[j] = Math.Min(ep[j], max);
            dp = ep;
        }
        var ans = dp[k];
        if (ans >= max) ans = -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 };

    #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