結果

問題 No.1715 Dinner 2
ユーザー kokatsukokatsu
提出日時 2021-10-24 22:06:03
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 946 ms / 2,000 ms
コード長 1,326 bytes
コンパイル時間 2,376 ms
コンパイル使用メモリ 201,140 KB
実行使用メモリ 48,436 KB
最終ジャッジ日時 2023-09-04 14:38:38
合計ジャッジ時間 12,430 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 660 ms
48,436 KB
testcase_12 AC 509 ms
28,980 KB
testcase_13 AC 423 ms
25,756 KB
testcase_14 AC 565 ms
31,960 KB
testcase_15 AC 514 ms
28,964 KB
testcase_16 AC 520 ms
32,060 KB
testcase_17 AC 493 ms
31,996 KB
testcase_18 AC 15 ms
4,636 KB
testcase_19 AC 25 ms
4,560 KB
testcase_20 AC 18 ms
4,636 KB
testcase_21 AC 15 ms
4,644 KB
testcase_22 AC 19 ms
4,688 KB
testcase_23 AC 23 ms
4,504 KB
testcase_24 AC 19 ms
4,608 KB
testcase_25 AC 73 ms
11,788 KB
testcase_26 AC 55 ms
11,784 KB
testcase_27 AC 56 ms
11,856 KB
testcase_28 AC 72 ms
11,900 KB
testcase_29 AC 68 ms
11,812 KB
testcase_30 AC 69 ms
11,832 KB
testcase_31 AC 72 ms
11,848 KB
testcase_32 AC 935 ms
35,088 KB
testcase_33 AC 946 ms
35,004 KB
testcase_34 AC 895 ms
35,084 KB
testcase_35 AC 835 ms
35,120 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 23 ms
4,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    int N, D;
    readf("%d %d\n", N, D);

    auto P = new long[](N), Q = new long[](N);
    foreach (i; 0 .. N) {
        readf("%d %d\n", P[i], Q[i]);
    }

    long M = long.min / 2;

    long ok = M, ng;
    while (ng - ok > 1) {
        long mid = (ok + ng) / 2;

        auto dp = new long[][](D, N);        
        foreach (i; 0 .. D) {
            dp[i][] = M;
        }

        foreach (i; 0 .. N) {
            if (-P[i] >= mid) {
                dp[0][i] = Q[i] - P[i];
            }
        }

        foreach (i; 0 .. D-1) {
            auto dpL = new long[](N+1), dpR = new long[](N+1);
            dpL[] = M, dpR[] = M;
            foreach (j; 0 .. N) {
                dpL[j+1] = max(dpL[j], dp[i][j]);
                dpR[N-j-1] = max(dpR[N-j], dp[i][N-j-1]);
            }

            foreach (j; 0 .. N) {
                long tmp = max(dpL[j], dpR[j+1]);
                if (tmp - P[j] >= mid) {
                    dp[i+1][j] = tmp + Q[j] - P[j];
                }
            }
        }

        bool isOK;
        foreach (i; 0 .. N) {
            if (dp[D-1][i] > M) {
                isOK = true;
                break;
            }
        }

        if (isOK) {
            ok = mid;
        }
        else {
            ng = mid;
        }
    }

    ok.writeln;
}
0