結果

問題 No.1 道のショートカット
ユーザー CleyLCleyL
提出日時 2022-09-10 16:12:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 1,311 bytes
コンパイル時間 951 ms
コンパイル使用メモリ 87,264 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-17 20:26:40
合計ジャッジ時間 3,448 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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,376 KB
testcase_04 AC 2 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,376 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 5 ms
4,376 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 6 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 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,376 KB
testcase_23 AC 17 ms
4,376 KB
testcase_24 AC 19 ms
4,376 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 9 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 4 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 4 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 7 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
using namespace std;
struct d{
  int s,t,y,m;
};
struct dd{
  int t,y,m;
};
struct k{
  int p,c,t;
  
  bool operator<(const k a) const {
    if(t == a.t){
      if(c == a.c){
        return p < a.p;
      }
      return c < a.c;
    }
    return t < a.t;
  }
};
int main(){
  int n,c,v;cin>>n>>c>>v;
  vector<vector<int>> Z(n,vector<int>(c+1,1000000));
  vector<d> A(v);
  vector<dd> B[n];
  for(int i = 0; v > i; i++){
    cin>>A[i].s;A[i].s--;
  }
  for(int i = 0; v > i; i++){
    cin>>A[i].t;A[i].t--;
  }
  for(int i = 0; v > i; i++){
    cin>>A[i].y;
  }
  for(int i = 0; v > i; i++){
    cin>>A[i].m;
  }
  for(int i = 0; v > i; i++){
    B[A[i].s].push_back({A[i].t,A[i].y,A[i].m});
  }

  //dijkstra
  priority_queue<k> X;
  X.push({0,c,0});
  Z[0][c] = 0;
  
  while(X.size()){
    auto x = X.top();X.pop();
    for(int i = 0; B[x.p].size() > i; i++){
      if(B[x.p][i].y > x.c)continue;
      if(Z[B[x.p][i].t][x.c-B[x.p][i].y] > Z[x.p][x.c]+B[x.p][i].m){
        Z[B[x.p][i].t][x.c-B[x.p][i].y] = Z[x.p][x.c]+B[x.p][i].m;
        X.push({B[x.p][i].t,x.c-B[x.p][i].y,Z[x.p][x.c]+B[x.p][i].m});
      }
    }
  }
  int ans = Z[n-1][0];
  for(int i = 0; c >= i; i++){
    ans = min(ans,Z[n-1][i]);
  }
  cout << (ans==1000000?-1:ans) << endl;
}
0