結果

問題 No.1 道のショートカット
ユーザー msm1993msm1993
提出日時 2019-04-16 12:52:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,904 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 87,692 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 22:18:26
合計ジャッジ時間 2,313 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <assert.h>
#include <ctype.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#define SZ(a) (int)(a).size()
#define FOR(i,a,b) for (int i=(a); i<=(b); ++i)
#define REP(i,n) for (int i=0; i<(n); ++i)
#define ALL(c) c.begin(), c.end()
#define CLR(c,n) memset(c, n, sizeof(c))
#define MCPY(d, s) memcpy(d, s, sizeof(d))
#define TR(it, c) for (auto it = c.begin();it != c.end(); ++it)
#define CONTAIN(it, c) (c.find(it) != c.end())
typedef vector<int> VI;
typedef pair<int, int> PII;
template <class T> void checkmin(T &a, T b) { if (b<a) a=b; }
template <class T> void checkmax(T &a, T b) { if (b>a) a=b; }
typedef long long LL;
const int INF=0x3F3F3F3F;

const int N=50, M=1500, C=300;
struct Edge {
  int from, to;
  int price, cost;
} e[M];
int head[N], nxt[M];
int dp[N][C+1];
int n, c, m;

int main(int argc, char *argv[]) {
  while (scanf("%d%d%d", &n, &c, &m) != EOF) {
    REP(i, m) scanf("%d", &e[i].from), --e[i].from;
    REP(i, m) scanf("%d", &e[i].to), --e[i].to;
    REP(i, m) scanf("%d", &e[i].price);
    REP(i, m) scanf("%d", &e[i].cost);
    CLR(head, -1);
    REP(i, m) {
      int d=e[i].to;
      nxt[i] = head[d];
      head[d] = i;
    }
    CLR(dp, INF);
    CLR(dp[0], 0);
    for (int i = 1; i < n; ++i) {
      for (int j = head[i]; j >= 0; j = nxt[j]) {
        for (int c1=0, c2=e[j].price; c2 <= c; ++c1, ++c2) {
          checkmin(dp[i][c2], dp[e[j].from][c1]+e[j].cost);
        }
      }
    }
    int ans = dp[n-1][c];
    printf("%d\n", ans == INF ? -1 : ans);
  }
}
0