結果

問題 No.1037 exhausted
ユーザー kk
提出日時 2021-02-04 17:30:42
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 424 ms / 2,000 ms
コード長 1,061 bytes
コンパイル時間 2,326 ms
コンパイル使用メモリ 212,852 KB
実行使用メモリ 35,012 KB
最終ジャッジ日時 2023-09-13 14:17:20
合計ジャッジ時間 8,040 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 424 ms
34,768 KB
testcase_13 AC 422 ms
34,696 KB
testcase_14 AC 411 ms
34,572 KB
testcase_15 AC 421 ms
34,960 KB
testcase_16 AC 408 ms
34,716 KB
testcase_17 AC 418 ms
34,716 KB
testcase_18 AC 411 ms
34,676 KB
testcase_19 AC 410 ms
34,748 KB
testcase_20 AC 392 ms
34,644 KB
testcase_21 AC 400 ms
35,012 KB
testcase_22 AC 387 ms
34,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
const long long INF = 1LL<<60;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, v, l;
  cin >> n >> v >> l;

  vector<int> x(n+2), y(n+2), c(n+2);
  x[n+1] = l;
  for (int i = 1; i <= n; i++)
    cin >> x[i] >> y[i] >> c[i];

  vector<vector<long long> > dp(n+2, vector<long long>(v+1));
  for (int i = 0; i < v; i++) dp[0][i] = INF;

  for (int i = 1; i <= n+1; i++) {
    queue<long long> q;
    multiset<long long> s;
    for (int j = 0; j <= v; j++) {
      // 給油する
      long long v1 = s.size() ? (*s.begin() + c[i]) : INF;

      // 給油しない
      int d = x[i] - x[i-1];
      long long v2 = (j + d) <= v ? dp[i-1][j+d] : INF;

      dp[i][j] = min(v1, v2);
      
      q.push(v2);
      s.insert(v2);

      if (q.size() > min(v, y[i])) {
        s.erase(s.find(q.front()));
        q.pop();
      }
    }
  }

  long long ret = INF;
  for (int i = 0; i <= v; i++)
    ret = min(ret, dp[n+1][i]);

  if (ret == INF)
    ret = -1;
  cout << ret << endl;
  
  return 0;
}
0