結果

問題 No.1 道のショートカット
コンテスト
ユーザー rpy3cpp
提出日時 2015-08-06 21:42:52
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 1,272 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 555 ms
コンパイル使用メモリ 20,824 KB
実行使用メモリ 15,488 KB
最終ジャッジ日時 2026-03-29 21:05:02
合計ジャッジ時間 5,850 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 16 WA * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def read_data():
    N = int(input())
    C = int(input())
    V = int(input())
    S = list(map(int, input().split()))
    T = list(map(int, input().split()))
    Y = list(map(int, input().split()))
    M = list(map(int, input().split()))
    cost = [[float('inf')] * N for i in range(N)]
    time = [[float('inf')] * N for i in range(N)]
    for s, t, y, m in zip(S, T, Y, M):
        cost[s-1][t-1] = y
        time[s-1][t-1] = m
    return N, C, V, cost, time


def solve(N, C, V, cost, time):
    INF = float('inf')
    dp = [[INF] * (C + 1) for i in range(N)]
    dp[0][0] = 0
    for pos in range(N):
        cost_pos = cost[pos]
        time_pos = time[pos]
        for np in range(pos + 1, N):
            nc = cost_pos[np]
            if nc == INF:
                continue
            nt = time_pos[np]
            dp_np = dp[np]
            for c, m in enumerate(dp[pos]):
                if m == INF:
                    continue
                ncc = nc + c
                if ncc <= C and dp_np[ncc] > nt + m:
                    dp_np[ncc] = nt + m
    min_time = min(dp[N-1])
    if min_time == INF:
        return -1
    else:
        return min_time

if __name__ == '__main__':
    N, C, V, cost, time = read_data()
    print(solve(N, C, V, cost, time))
0