結果

問題 No.1 道のショートカット
ユーザー tnoda_tnoda_
提出日時 2015-02-04 01:38:01
言語 Go
(1.22.1)
結果
AC  
実行時間 22 ms / 5,000 ms
コード長 1,093 bytes
コンパイル時間 12,194 ms
コンパイル使用メモリ 201,772 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 21:38:12
合計ジャッジ時間 14,111 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 16 ms
4,376 KB
testcase_09 AC 11 ms
4,376 KB
testcase_10 AC 15 ms
4,380 KB
testcase_11 AC 17 ms
4,376 KB
testcase_12 AC 22 ms
4,376 KB
testcase_13 AC 21 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 18 ms
4,376 KB
testcase_24 AC 14 ms
4,380 KB
testcase_25 AC 5 ms
4,376 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 15 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 19 ms
4,380 KB
testcase_30 AC 4 ms
4,380 KB
testcase_31 AC 9 ms
4,376 KB
testcase_32 AC 12 ms
4,380 KB
testcase_33 AC 10 ms
4,380 KB
testcase_34 AC 18 ms
4,376 KB
testcase_35 AC 12 ms
4,376 KB
testcase_36 AC 14 ms
4,380 KB
testcase_37 AC 11 ms
4,380 KB
testcase_38 AC 3 ms
4,376 KB
testcase_39 AC 4 ms
4,380 KB
testcase_40 AC 6 ms
4,380 KB
testcase_41 AC 3 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
)

func min(x, y int) int {
	if y < x {
		return y
	}
	return x
}

type e struct {
	v int
	c int
	t int
}

func main() {
	Inf := 1 << 28
	var N, C, V int
	fmt.Scan(&N, &C, &V)
	var S, T, Y, M [1510]int
	for i := 0; i < V; i++ {
		fmt.Scan(&S[i])
	}
	for i := 0; i < V; i++ {
		fmt.Scan(&T[i])
	}
	for i := 0; i < V; i++ {
		fmt.Scan(&Y[i])
	}
	for i := 0; i < V; i++ {
		fmt.Scan(&M[i])
	}
	E := make([][]e, N)
	for i := 0; i < V; i++ {
		from, to, cost, time := S[i], T[i], Y[i], M[i]
		from--
		to--
		E[from] = append(E[from], e{v: to, c: cost, t: time})
	}
	dp := make([][]int, N)
	for i := 0; i < N; i++ {
		dp[i] = make([]int, C+1)
		for j := 0; j <= C; j++ {
			dp[i][j] = Inf
		}
	}
	dp[0][C] = 0
	for i := 0; i < N; i++ {
		for c0 := C; c0 > 0; c0-- {
			if dp[i][c0] == Inf {
				continue
			}
			for _, e := range E[i] {
				if c0-e.c < 0 {
					continue
				}
				dp[e.v][c0-e.c] = min(dp[e.v][c0-e.c], dp[i][c0]+e.t)
			}
		}
	}
	res := Inf
	for i := 0; i < C; i++ {
		res = min(res, dp[N-1][i])
	}
	if res == Inf {
		res = -1
	}
	fmt.Println(res)
}
0