結果

問題 No.1 道のショートカット
ユーザー pessimist
提出日時 2024-10-20 16:08:55
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 948 bytes
コンパイル時間 2,254 ms
コンパイル使用メモリ 204,848 KB
最終ジャッジ日時 2025-02-24 21:51:17
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(nullptr)->sync_with_stdio(false);
  int N, C, V; cin >> N >> C >> V;
  vector<int> S(V), T(V), Y(V), M(V);
  for(auto& x: S) cin >> x, --x;
  for(auto& x: T) cin >> x, --x;
  for(auto& x: Y) cin >> x;
  for(auto& x: M) cin >> x;
  
  vector<vector<tuple<int, int, int>>> edge(N);
  for(int i = 0; i < V; ++i){
    edge[S[i]].emplace_back(T[i], Y[i], M[i]);
  } 

  const int inf = 1e9;
  vector dp(N, vector(C + 1, inf));
  dp.at(0).at(C) = 0;
  for(int i = 0; i < N; ++i){
    for(int k = C; k >= 0; --k){
      if(dp.at(i).at(k) == inf) continue;
      for(const auto& [to, cost, time]: edge[i]){
        if(k < cost) continue;
        dp.at(to).at(k - cost) = min(dp.at(to).at(k - cost), dp.at(i).at(k) + time);
      }
    }
  }
  int minTime = *min_element(dp.at(N - 1).begin(), dp.at(N - 1).end());
  if(minTime == inf) minTime = -1;
  cout << minTime << endl;
  return 0;
}
0