結果

問題 No.1 道のショートカット
ユーザー zezerozezero
提出日時 2022-04-05 18:59:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,524 bytes
コンパイル時間 3,354 ms
コンパイル使用メモリ 168,500 KB
実行使用メモリ 4,564 KB
最終ジャッジ日時 2023-08-17 22:33:17
合計ジャッジ時間 5,505 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,500 KB
testcase_37 AC 2 ms
4,564 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <cmath>
#include <atcoder/all>
#include <tuple>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < int(n);i++)

int dp[51][301];
struct Edge{
  int to,time,cost;
};
int main(){
  int n,c,v;
  cin >> n >> c >> v;
  vector<int> s(v);
  vector<int> t(v);
  vector<int> y(v);
  vector<int> m(v);
  vector<vector<Edge>> g(n);
  rep(i,v) cin >> s[i];
  rep(i,v) cin >> t[i];
  rep(i,v) cin >> y[i];
  rep(i,v) cin >> m[i];
  rep(i,v){
    Edge x;
    x.to = t[i]-1;
    x.time = m[i];
    x.cost = y[i];
    g[s[i]-1].push_back(x);
  }
  for (int i = 0; i < n;i++){
    for (int j = 0; j <= c;j++){
      dp[i][j] = 1e9;
    }
  }
  dp[0][c] = 0;
  for (int i = 0; i < n;i++){
    for (int j = c; j >= 0;j--){
      for (auto ex:g[i]){
        if (j-ex.cost < 0) continue;
        //printf("(to,j-cost) = (%d,%d)\n",ex.to,j-ex.cost);
        //cout << endl;
        dp[ex.to][j-ex.cost] = min(dp[ex.to][j-ex.cost],dp[i][j]+ex.time);
      }
    }
  }  
  int ans = 1e9;
  for (int i = 0; i <= c;i++){
    if (dp[n-1][i] < ans) ans = dp[n-1][i];
  }
  if (ans == 1e9) ans = -1; 
  cout << ans << endl;

  //for (int i = 0; i < n;i++){
  //  for (int j = 0; j <= 10; j++){
  //    if (dp[i][j] >= 1e9) cout << "F "; 
  //    else cout << dp[i][j] << " ";
  //  }
  //  cout << endl;
  //}

  
  return 0;
}
0