結果

問題 No.1715 Dinner 2
ユーザー nawawannawawan
提出日時 2021-10-22 22:09:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 176 ms / 2,000 ms
コード長 1,079 bytes
コンパイル時間 2,049 ms
コンパイル使用メモリ 207,364 KB
実行使用メモリ 7,244 KB
最終ジャッジ日時 2023-10-24 13:21:03
合計ジャッジ時間 4,802 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 134 ms
6,452 KB
testcase_12 AC 109 ms
5,924 KB
testcase_13 AC 91 ms
5,396 KB
testcase_14 AC 111 ms
5,924 KB
testcase_15 AC 111 ms
5,924 KB
testcase_16 AC 106 ms
5,660 KB
testcase_17 AC 68 ms
4,868 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 6 ms
4,348 KB
testcase_20 AC 4 ms
4,348 KB
testcase_21 AC 4 ms
4,348 KB
testcase_22 AC 5 ms
4,348 KB
testcase_23 AC 6 ms
4,348 KB
testcase_24 AC 4 ms
4,348 KB
testcase_25 AC 14 ms
4,348 KB
testcase_26 AC 9 ms
4,348 KB
testcase_27 AC 10 ms
4,348 KB
testcase_28 AC 13 ms
4,348 KB
testcase_29 AC 13 ms
4,348 KB
testcase_30 AC 13 ms
4,348 KB
testcase_31 AC 14 ms
4,348 KB
testcase_32 AC 174 ms
7,244 KB
testcase_33 AC 172 ms
7,244 KB
testcase_34 AC 175 ms
7,244 KB
testcase_35 AC 176 ms
7,244 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 1 ms
4,348 KB
testcase_38 AC 6 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
    int N, D;
    cin >> N >> D;
    vector<int> P(N), Q(N);
    for(int i = 0; i < N; i++) cin >> P[i] >> Q[i];
    int ub = 0, lb = -1000000000;
    int INF = 2000000000;
    while(ub - lb > 1){
        int mid = (ub + lb) / 2;
        vector<vector<int>> dp(D, vector<int>(N, -INF));
        bool f = false;
        for(int i = 0; i < N; i++){
            if(-P[i] >= mid) dp[0][i] = -P[i] + Q[i];
        }
        for(int i = 0; i < D - 1; i++){
            vector<int> L(N + 1, -INF), R(N + 1, -INF);
            for(int j = 0; j < N; j++){
                L[j + 1] = max(L[j], dp[i][j]);
                R[N - 1 - j] = max(R[N - j], dp[i][N - 1 - j]);
            }
            for(int j = 0; j < N; j++){
                int t = max(R[j + 1], L[j]);
                if(t - P[j] >= mid) dp[i + 1][j] = t - P[j] + Q[j];
            }
        }
        for(int i = 0; i < N; i++){
            if(dp[D - 1][i] != -INF) f = true;
        }
        if(f) lb = mid;
        else ub = mid;
    }
    cout << lb << endl;
}
0