結果
問題 | No.1 道のショートカット |
ユーザー | fmhr |
提出日時 | 2015-04-25 03:09:22 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 128 ms / 5,000 ms |
コード長 | 2,077 bytes |
コンパイル時間 | 83 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 11,264 KB |
最終ジャッジ日時 | 2024-07-20 16:12:27 |
合計ジャッジ時間 | 3,252 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
10,752 KB |
testcase_01 | AC | 30 ms
10,752 KB |
testcase_02 | AC | 32 ms
10,752 KB |
testcase_03 | AC | 32 ms
10,752 KB |
testcase_04 | AC | 31 ms
10,752 KB |
testcase_05 | AC | 30 ms
10,752 KB |
testcase_06 | AC | 30 ms
10,752 KB |
testcase_07 | AC | 31 ms
10,752 KB |
testcase_08 | AC | 42 ms
11,008 KB |
testcase_09 | AC | 35 ms
10,880 KB |
testcase_10 | AC | 41 ms
10,880 KB |
testcase_11 | AC | 63 ms
10,880 KB |
testcase_12 | AC | 92 ms
11,264 KB |
testcase_13 | AC | 80 ms
11,264 KB |
testcase_14 | AC | 32 ms
10,752 KB |
testcase_15 | AC | 32 ms
10,880 KB |
testcase_16 | AC | 33 ms
10,752 KB |
testcase_17 | AC | 32 ms
10,752 KB |
testcase_18 | AC | 32 ms
10,880 KB |
testcase_19 | AC | 33 ms
10,752 KB |
testcase_20 | AC | 38 ms
10,880 KB |
testcase_21 | AC | 34 ms
10,880 KB |
testcase_22 | AC | 34 ms
10,752 KB |
testcase_23 | AC | 128 ms
11,008 KB |
testcase_24 | AC | 122 ms
11,008 KB |
testcase_25 | AC | 47 ms
10,752 KB |
testcase_26 | AC | 38 ms
10,752 KB |
testcase_27 | AC | 100 ms
10,880 KB |
testcase_28 | AC | 31 ms
11,008 KB |
testcase_29 | AC | 45 ms
11,136 KB |
testcase_30 | AC | 32 ms
10,752 KB |
testcase_31 | AC | 42 ms
10,752 KB |
testcase_32 | AC | 49 ms
11,008 KB |
testcase_33 | AC | 39 ms
11,008 KB |
testcase_34 | AC | 98 ms
11,136 KB |
testcase_35 | AC | 33 ms
10,880 KB |
testcase_36 | AC | 36 ms
10,880 KB |
testcase_37 | AC | 33 ms
10,752 KB |
testcase_38 | AC | 31 ms
10,752 KB |
testcase_39 | AC | 33 ms
10,752 KB |
testcase_40 | AC | 32 ms
10,880 KB |
testcase_41 | AC | 31 ms
10,752 KB |
testcase_42 | AC | 31 ms
10,880 KB |
testcase_43 | AC | 32 ms
11,008 KB |
ソースコード
# coding:utf-8 import sys def int0(n): return int(n)-1 N = int(input()) # 街の数 C = int(input()) # 所持金 V = int(input()) # 道の数 S = list(map(int0, input().split())) # S->T T = list(map(int0, input().split())) # Y = list(map(int, input().split())) # cost[S][T] M = list(map(int, input().split())) # time[S][T] # cost = [[[C*N+1] for a in range(N)] for b in range(N)] # time = [[[1000*N+1] for c in range(N)] for d in range(N)] # cost = [[[] for a in range(N)] for b in range(N)] # # time = [[[] for c in range(N)] for d in range(N)] # # for i in range(N): # cost[i][i].append([0]) # # time[i][i].append(0) # # root = [] # cost_and_time = [[] for i in range(N)] # for i in range(V): # # cost[S[i]][T[i]].append([Y[i], M[i]]) # # time[S[i]][T[i]].append(M[i]) # root[S[i]].appned(T[i]) # cost_and_time = cost[S[i]][T[i]].append([Y[i], M[i]]) # next_root = root[0] # p = 0 # while not next_root: # for i in root[0]: # for cost in cost[p][i]: root = [[] for i in range(N)] for i in range(V): root[S[i]].append([T[i], Y[i], M[i]]) MAX = 9999999 dp = [[MAX for i in range(C+1)] for j in range(N)] dp[0][C] = 0 # dp[ポイント][総交通費] = 経過時間 for i in range(N): for j in range(C, 0, -1): if dp[i][j] == MAX: continue for kroot in root[i]: if kroot[1] <= j: dp[kroot[0]][j-kroot[1]] = min(dp[kroot[0]][j-kroot[1]], dp[i][j]+kroot[2]) ans = [] for j in range(C+1): if dp[N-1][j] == MAX: continue ans.append(dp[N-1][j]) if len(ans) == 0: print('-1') else: print(min(ans)) # for k in range(N): # for i in range(N): # for j in range(N): # cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]) # # if cost[0][N-1]>C: # print('-1') # sys.exit(0) # # for k in range(N): # for i in range(N): # for j in range(N): # # if cost[i][k]+cost[k][j]<=C: # time[i][j] = min(time[i][j], time[i][k]+time[k][j]) # print(cost[0]) # print(time[0]) # print(time[0][N-1])