結果

問題 No.1 道のショートカット
ユーザー yukudoyukudo
提出日時 2017-05-19 13:06:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,600 bytes
コンパイル時間 1,691 ms
コンパイル使用メモリ 154,124 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 22:05:59
合計ジャッジ時間 3,158 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,true):false;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,true):false;}

int nextInt() { int x; scanf("%d", &x); return x;}

int memo[51][310];
struct State {
  int pos, dist, money;
  bool operator < (const State& o) const {
    return dist > o.dist;
  }
  int& ref() {
    return memo[pos][money];
  }
};

int S[1500], T[1500], Y[1500], M[1500];
struct E {
  int s, t, y, m;
};
vector<E> es[51];

int main2() {
  REP(i, 51) es[i].clear();
  int N = nextInt();
  int C = nextInt();
  int V = nextInt();
  REP(i, V) S[i] = nextInt();
  REP(i, V) T[i] = nextInt();
  REP(i, V) Y[i] = nextInt();
  REP(i, V) M[i] = nextInt();
  REP(i, V) {
    es[S[i]].push_back( (E){S[i], T[i], Y[i], M[i]} );
  }
  const int INF = 987654321;
  REP(i, 51) REP(j, 310) memo[i][j] = INF;

  int ans = INF;
  priority_queue<State> pq;
  pq.push( (State){1, 0, 0} );
  memo[1][0] = 0;

  while (!pq.empty()) {
    State cur = pq.top(); pq.pop();
    if (cur.dist != cur.ref()) continue;
    if (cur.pos == N) {
      ans = cur.dist;
      break;
    }
    for (E e : es[cur.pos]) {
      State next = (State) { e.t, cur.dist + e.m, cur.money + e.y };
      if (next.money > C) continue;
      if (next.ref() <= next.dist) continue;
      next.ref() = next.dist;
      pq.push(next);
    }
  }
  if (ans >= INF / 2) ans = -1;
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}
0