結果

問題 No.1 道のショートカット
ユーザー mh72012246mh72012246
提出日時 2016-10-28 16:30:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 2,119 bytes
コンパイル時間 637 ms
コンパイル使用メモリ 78,668 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 22:01:25
合計ジャッジ時間 2,068 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <vector>
#include <array>
#include <queue>
#include <set>
#include <sstream>   // istringstream
#include <algorithm> // sort
#include <utility>   // pair
#include <cfloat>    // DBL_MAX

typedef long long ll;
using namespace std;

struct log {
  int pos;
  int cost;
  int time;
};

int main(){
  ll N,C,V; // [50],[300],[1500]
  cin >> N >> C >> V;

  vector<int> ss(V), ts(V), cs(V), ms(V);
  for(int i=0; i<V; i++){ cin >> ss[i]; }
  for(int i=0; i<V; i++){ cin >> ts[i]; }
  for(int i=0; i<V; i++){ cin >> cs[i]; }
  for(int i=0; i<V; i++){ cin >> ms[i]; }

  auto gt = [](struct log l, struct log r)->bool {
    return l.time > r.time;
  }; // increacing order of time
  priority_queue<struct log, vector<struct log>,
                 decltype(gt)> roots(gt);

  struct log start = {1,0,0};
  roots.push(start);

  while(true){
    if(roots.empty()) { break; }
    struct log crr = roots.top();
    roots.pop();

    //cout<<crr.pos<<" "<<crr.cost<<" "<<crr.time<<endl;

    if(crr.pos == N){ // goal
      cout << crr.time << endl;
      return 0;
    }

    for(int i=0; i<V; i++){
      if(ss[i]!=crr.pos) { continue; }
      if(cs[i]+crr.cost > C) { continue; }
      struct log next = {ts[i], crr.cost+cs[i], crr.time+ms[i]};
      roots.push(next);
    }
  }

  cout << -1 << endl;

  //// TLE, search all root whose cost<C
  // queue<struct log> roots;
  // struct log tmp = {1,0,0};
  // roots.push(tmp);
  // int minTime = maxN*maxM;

  // while(true){
  //   if(roots.empty()){ break; }

  //   struct log crr  = roots.front();

  //   for(int i=0; i<V; i++){
  //     if(ss[i]!=crr.pos){ continue; }

  //     if(crr.cost + cs[i] <= C){
  //       if(ts[i]==N){ // goal
  //         minTime = min(minTime, ms[i]+crr.time);
  //       } else {
  //         tmp.pos  = ts[i];
  //         tmp.cost = cs[i]+crr.cost;
  //         tmp.time = ms[i]+crr.time;
  //         roots.push(tmp);
  //       }
  //     }
  //   }
  //   roots.pop();
  // }

  // //
  // if(minTime == maxN*maxM){
  //   minTime = -1;
  // }
  // cout << minTime << endl;

  return 0;
}
0