結果

問題 No.1 道のショートカット
ユーザー bellangeldindonbellangeldindon
提出日時 2019-05-15 17:32:51
言語 Python2
(2.7.18)
結果
AC  
実行時間 271 ms / 5,000 ms
コード長 1,200 bytes
コンパイル時間 322 ms
コンパイル使用メモリ 6,748 KB
実行使用メモリ 19,888 KB
最終ジャッジ日時 2023-09-27 22:19:15
合計ジャッジ時間 4,938 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,892 KB
testcase_01 AC 11 ms
5,948 KB
testcase_02 AC 12 ms
5,920 KB
testcase_03 AC 12 ms
5,888 KB
testcase_04 AC 12 ms
6,140 KB
testcase_05 AC 11 ms
5,992 KB
testcase_06 AC 12 ms
6,012 KB
testcase_07 AC 12 ms
5,896 KB
testcase_08 AC 144 ms
15,268 KB
testcase_09 AC 86 ms
11,592 KB
testcase_10 AC 147 ms
14,316 KB
testcase_11 AC 143 ms
14,720 KB
testcase_12 AC 271 ms
19,888 KB
testcase_13 AC 222 ms
19,036 KB
testcase_14 AC 14 ms
6,176 KB
testcase_15 AC 11 ms
5,844 KB
testcase_16 AC 30 ms
7,424 KB
testcase_17 AC 11 ms
6,140 KB
testcase_18 AC 18 ms
6,368 KB
testcase_19 AC 16 ms
6,276 KB
testcase_20 AC 32 ms
7,256 KB
testcase_21 AC 18 ms
6,204 KB
testcase_22 AC 15 ms
6,132 KB
testcase_23 AC 162 ms
12,340 KB
testcase_24 AC 122 ms
10,796 KB
testcase_25 AC 27 ms
6,796 KB
testcase_26 AC 21 ms
6,208 KB
testcase_27 AC 193 ms
15,224 KB
testcase_28 AC 11 ms
6,068 KB
testcase_29 AC 179 ms
13,888 KB
testcase_30 AC 31 ms
6,628 KB
testcase_31 AC 93 ms
7,424 KB
testcase_32 AC 106 ms
11,672 KB
testcase_33 AC 82 ms
9,796 KB
testcase_34 AC 130 ms
11,112 KB
testcase_35 AC 67 ms
7,768 KB
testcase_36 AC 136 ms
12,460 KB
testcase_37 AC 85 ms
9,448 KB
testcase_38 AC 14 ms
6,256 KB
testcase_39 AC 19 ms
6,424 KB
testcase_40 AC 40 ms
8,208 KB
testcase_41 AC 19 ms
6,360 KB
testcase_42 AC 11 ms
5,948 KB
testcase_43 AC 11 ms
5,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(raw_input())
C = int(raw_input())
V = int(raw_input())
S = map(int, raw_input().split())
T = map(int, raw_input().split())
Y = map(int, raw_input().split())
M = map(int, raw_input().split())
road = []
for i in range(0, V):
	road.append([S[i]-1, T[i]-1, Y[i], M[i]])
road.sort(key=lambda val: val[0])
dp = []
for i in range(0, V+1):
	lst = []
	for j in range(0, N):
		lst.append([])
	dp.append(lst)
dp[0][0].append([0, C])
for i in range(0, V):
	for j in range(0, N):
		for k in range(0, len(dp[i][j])):
			dp[i+1][j].append(dp[i][j][k])
	for j in range(0, N):
		if j == road[i][0]:
			next = road[i][1]
			for k in range(0, len(dp[i][j])):
				newtime = dp[i][j][k][0] + road[i][3]
				newcost = dp[i][j][k][1] - road[i][2]
				flag = True
				for p in range(0, len(dp[i+1][next])):
					time = dp[i+1][next][p][0]
					cost = dp[i+1][next][p][1]
					if time < newtime and newcost < cost:
						flag = False
						break
				if flag: dp[i+1][next].append([newtime, newcost])
if dp[V][N-1] == []: print -1
else:
	min = 1000000000
	for i in range(0, len(dp[V][N-1])):
		if dp[V][N-1][i][0] < min and dp[V][N-1][i][1] >= 0: min = dp[V][N-1][i][0]
	if min == 1000000000: print -1
	else: print min
0