結果

問題 No.1 道のショートカット
ユーザー moyashi_senpaimoyashi_senpai
提出日時 2016-08-17 17:08:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,549 bytes
コンパイル時間 716 ms
コンパイル使用メモリ 83,832 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 21:57:59
合計ジャッジ時間 2,418 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 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 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,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 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,376 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 2 ms
4,376 KB
testcase_40 AC 2 ms
4,376 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 <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;

struct edge {
	int to, cost, time;
};

int main() {
	int n,c,v;
	scanf("%d %d %d", &n, &c, &v);
	vector<vector<edge>> graph(n, vector<edge>());
	vector<int> S, T, Y, M;
	for (int i = 0; v > i; i++) {
		int s;
		scanf("%d", &s);
		S.push_back(s-1);
	}
	for (int i = 0; v > i; i++) {
		int t;
		scanf("%d", &t);
		T.push_back(t-1);
	}
	for (int i = 0; v > i; i++) {
		int y;
		scanf("%d", &y);
		Y.push_back(y);
	}
	for (int i = 0; v > i; i++) {
		int m;
		scanf("%d", &m);
		M.push_back(m);
	}

	for (int i = 0; v > i; i++) {
		graph[S[i]].push_back({T[i], Y[i], M[i]});
	}

	array<array<int, 301>, 55> dp;
	for (auto itr = dp.begin(); itr != dp.end(); itr++) {
		fill(itr->begin(), itr->end(), INT_MAX);
	}
	dp[0][c] = 0;
	for (int i = 0; n-1 > i; i++) {
		for (int j = 0; c >= j; j++) {
			if (dp[i][j] != INT_MAX) {
				for (auto itr = graph[i].begin(); itr != graph[i].end(); itr++) {
					if (j - itr->cost >= 0) {
						dp[itr->to][j - itr->cost] = min(dp[itr->to][j - itr->cost], dp [i] [j] + itr->time);
					}
				}
			}
		}
	}
	int ans = *min_element(dp[n - 1].begin(), dp[n - 1].end());
	printf("%d\n", ans == INT_MAX ? -1 : ans);
	return 0;
}
0