結果

問題 No.1 道のショートカット
ユーザー yukudoyukudo
提出日時 2017-05-19 12:42:41
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,590 bytes
コンパイル時間 1,323 ms
コンパイル使用メモリ 153,404 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 13:07:57
合計ジャッジ時間 2,746 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 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 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 WA -
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 WA -
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 2 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, money;
  bool operator < (const State& o) const {
    return memo[pos][money] > memo[o.pos][o.money];
  }
  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} );
  memo[1][0] = 0;
  
  while (!pq.empty()) {
    State cur = pq.top(); pq.pop();
    if (cur.pos == N) {
      ans = memo[cur.pos][cur.money];
      break;
    }
    for (E e : es[cur.pos]) {
      State next = (State) { e.t, cur.money + e.y };
      if (next.money > C) continue;
      if (next.ref() <= cur.ref() + e.m) continue;
      next.ref() = cur.ref() + e.m;
      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