結果

問題 No.1715 Dinner 2
ユーザー bluemeganebluemegane
提出日時 2021-10-24 10:31:22
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,243 bytes
コンパイル時間 805 ms
コンパイル使用メモリ 112,256 KB
実行使用メモリ 50,964 KB
最終ジャッジ日時 2024-04-09 21:24:58
合計ジャッジ時間 6,456 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
26,092 KB
testcase_01 AC 22 ms
26,208 KB
testcase_02 AC 22 ms
24,028 KB
testcase_03 AC 23 ms
24,156 KB
testcase_04 AC 21 ms
23,772 KB
testcase_05 WA -
testcase_06 AC 22 ms
26,216 KB
testcase_07 WA -
testcase_08 AC 22 ms
24,112 KB
testcase_09 AC 22 ms
26,100 KB
testcase_10 WA -
testcase_11 AC 353 ms
46,608 KB
testcase_12 AC 258 ms
49,368 KB
testcase_13 AC 229 ms
44,124 KB
testcase_14 AC 277 ms
47,492 KB
testcase_15 AC 323 ms
45,688 KB
testcase_16 AC 282 ms
46,520 KB
testcase_17 AC 181 ms
46,560 KB
testcase_18 WA -
testcase_19 AC 25 ms
26,436 KB
testcase_20 AC 22 ms
24,024 KB
testcase_21 AC 21 ms
24,108 KB
testcase_22 WA -
testcase_23 AC 23 ms
24,280 KB
testcase_24 AC 23 ms
23,896 KB
testcase_25 AC 51 ms
31,232 KB
testcase_26 AC 42 ms
30,452 KB
testcase_27 AC 41 ms
26,424 KB
testcase_28 AC 46 ms
30,560 KB
testcase_29 AC 53 ms
30,812 KB
testcase_30 AC 48 ms
30,052 KB
testcase_31 AC 51 ms
30,396 KB
testcase_32 AC 419 ms
50,964 KB
testcase_33 AC 391 ms
48,632 KB
testcase_34 AC 418 ms
46,828 KB
testcase_35 AC 470 ms
48,748 KB
testcase_36 AC 22 ms
24,112 KB
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

public class Hello
{
    public static int max1, max2, tmax1, tmax2, max1i, max2i, tmax1i, tmax2i;
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var d = int.Parse(line[1]);
        var p = new int[n];
        var q = new int[n];
        var r = new int[n];
        for (int i = 0; i < n; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            p[i] = int.Parse(line[0]);
            q[i] = int.Parse(line[1]);
            r[i] = q[i] - p[i];
        }
        getAns(n, d, p, q, r);

    }
    static void getAns(int n, int d, int[] p, int[] q, int[] r)
    {
        var ok = -100000000;
        var ng = 0;
        while (ng - ok > 1)
        {
            var mid = ok + (ng - ok) / 2;
            if (check(n, d, p, q, r, mid)) ok = mid;
            else ng = mid;
        }
        Console.WriteLine(ok);
    }
    static void setMax(int t,int i)
    {
        if (t >= max1) { max2 = max1; max2i = max1i; max1 = t; max1i = i; }
        else if (t >= max2) { max2 = t; max2i = i;   }
    }
    static void setTmax(int t , int i)
    {
        if (t >= tmax1) { tmax2 = tmax1; tmax2i = tmax1i; tmax1 = t; tmax1i = i; }
        else if (t >= tmax2) { tmax2 = t; tmax2i = i;   }
    }

    static bool check(int n, int d, int[] p, int[] q, int[] r, int t)
    {
        var dp = new int[d + 1, n];
        for (int i = 0; i < d + 1; i++)
            for (int j = 0; j < n; j++) dp[i, j] = int.MinValue;
        max1 = int.MinValue;
        max2 = int.MinValue;
        for (int i = 0; i < n; i++)
        {
            if (-p[i] >= t) dp[1, i] = r[i];
            setMax( dp[1,i] ,i);
        }
        if (max1 == int.MinValue) return false;
        for (int i = 2; i <= d; i++)
        {
            tmax1 = int.MinValue;
            tmax2 = int.MinValue;
            for (int j = 0; j < n; j++)
            {
                if (j == max1i)
                {
                    if (max2 == int.MinValue) { dp[i, j] = int.MinValue; setTmax(int.MinValue, j); }
                    else
                    {
                        if (dp[i - 1, max2i] - p[j] < t) 
                        {
                            dp[i, j] = int.MinValue; 
                            setTmax(int.MinValue, j);
                        }
                        else
                        {
                            dp[i, j] = dp[i - 1, max2i] + r[j];
                            setTmax(dp[i - 1, max2i] + r[j],j);
                        }
                    }
                }
                else
                {
                    if (dp[i - 1, max1i] - p[j] < t) { dp[i, j] = int.MinValue; setTmax(int.MinValue, j); }
                    else
                    {
                        dp[i, j] = dp[i - 1, max1i] + r[j];
                        setTmax(dp[i - 1, max1i] + r[j], j);
                    }
                }
            }
            max1 = tmax1;
            max2 = tmax2;
            max1i = tmax1i;
            max2i = tmax2i;
        }
        for (int i = 0; i < n; i++)
        {
            if (dp[d, i] != int.MinValue) { return true; }
        }
        return false;
    }
}
0