結果

問題 No.1 道のショートカット
ユーザー illanastyillanasty
提出日時 2021-12-23 19:43:38
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,649 bytes
コンパイル時間 3,181 ms
コンパイル使用メモリ 135,628 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 21:10:11
合計ジャッジ時間 6,636 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>


using namespace std;
using LL = long long;
using LD = long double;


#define ALL(v) begin(v), end(v)
#define REP(i, n) for (LL i = 0; (i) < (LL)(n); ++(i))
#define REPR(i, n) for (LL i = (LL)(n)-1; (i) >= 0; --(i))
#define REP2(i, n, m) for (LL i = (LL)(n); (i) < (LL)(m); ++(i))
#define REP2R(i, n, m) for (LL i = (LL)(n)-1; (i) >= (LL)(m); --(i))


#define INF  1000000000
#define MAXV 55
#define MAXC 305


int V, C, E;
int S[MAXV], T[MAXV], Y[MAXV], M[MAXV];
int DP[MAXV][MAXC];


int main() {
  cin >> V >> C >> E;
  REP(i, E) {
    cin >> S[i];
    --S[i];
  }
  REP(i, E) {
    cin >> T[i];
    --T[i];
  }
  REP(i, E) cin >> Y[i];
  REP(i, E) cin >> M[i];

  REP(i, MAXV) REP(j, MAXC) DP[i][j] = INF;

  using Data = tuple<int,int,int>;

  priority_queue<Data,vector<Data>,greater<Data>> que;
  que.push({0, 0, C});
  DP[0][C] = 0;

  while (!que.empty()) {
    auto [dis, now, coin] = que.top();
    que.pop();

    if (DP[now][coin] < dis) continue;

    REP(i, E) {
      if (S[i] != now) continue;
      if (Y[i] > coin) continue;
      if (DP[T[i]][coin - Y[i]] > dis + M[i]) {
        DP[T[i]][coin - Y[i]] = dis + M[i];
        que.push({dis + M[i], T[i], coin - Y[i]});
      }
    }
  }

  int ans = INF;
  REP(i, MAXC) ans = min(ans, DP[V-1][i]);

  cout << (ans == INF ? -1 : ans) << endl;
  return 0;
}
0