結果

問題 No.1715 Dinner 2
ユーザー SSRSSSRS
提出日時 2021-10-22 21:32:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,149 bytes
コンパイル時間 1,877 ms
コンパイル使用メモリ 173,420 KB
実行使用メモリ 7,232 KB
最終ジャッジ日時 2023-10-24 12:26:10
合計ジャッジ時間 4,725 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
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 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 101 ms
5,912 KB
testcase_13 WA -
testcase_14 AC 97 ms
5,912 KB
testcase_15 WA -
testcase_16 AC 94 ms
5,648 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 153 ms
7,232 KB
testcase_33 AC 146 ms
7,232 KB
testcase_34 AC 155 ms
7,232 KB
testcase_35 AC 156 ms
7,232 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int INF = 100000000;
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 tv = -INF, fv = 0;
  while (fv - tv > 1){
    int mid = (tv + fv) / 2;
    vector<vector<int>> dp(N, vector<int>(D, -INF));
    for (int i = 0; i < D; i++){
      if (-P[i] >= mid){
        dp[0][i] = -P[i] + Q[i];
      }
    }
    for (int i = 0; i < N - 1; i++){
      vector<int> L(D + 1);
      L[0] = -INF;
      for (int j = 0; j < D; j++){
        L[j + 1] = max(L[j], dp[i][j]);
      }
      vector<int> R(D + 1);
      R[D] = -INF;
      for (int j = D - 1; j >= 0; j--){
        R[j] = max(R[j + 1], dp[i][j]);
      }
      for (int j = 0; j < D; j++){
        int mx = max(L[j], R[j + 1]);
        if (mx - P[j] >= mid){
          assert(mx != -INF);
          dp[i + 1][j] = mx - P[j] + Q[j];
        }
      }
    }
    bool ok = false;
    for (int i = 0; i < D; i++){
      if (dp[N - 1][i] != -INF){
        ok = true;
      }
    }
    if (ok){
      tv = mid;
    } else {
      fv = mid;
    }
  }
  cout << tv << endl;
}
0