結果

問題 No.1 道のショートカット
ユーザー aru aruaru aru
提出日時 2020-06-20 11:06:50
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 1,981 bytes
コンパイル時間 11,477 ms
コンパイル使用メモリ 214,100 KB
実行使用メモリ 7,816 KB
最終ジャッジ日時 2023-09-22 13:48:44
合計ジャッジ時間 33,607 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 856 ms
5,572 KB
testcase_09 AC 689 ms
5,576 KB
testcase_10 AC 116 ms
4,380 KB
testcase_11 AC 318 ms
4,380 KB
testcase_12 AC 2,585 ms
7,808 KB
testcase_13 AC 2,345 ms
7,816 KB
testcase_14 AC 32 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 WA -
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 21 ms
4,384 KB
testcase_19 AC 285 ms
5,548 KB
testcase_20 AC 124 ms
4,380 KB
testcase_21 WA -
testcase_22 AC 152 ms
4,384 KB
testcase_23 AC 2,074 ms
5,576 KB
testcase_24 AC 4,355 ms
5,580 KB
testcase_25 AC 1,208 ms
5,572 KB
testcase_26 AC 1,108 ms
5,556 KB
testcase_27 AC 1,249 ms
5,576 KB
testcase_28 AC 8 ms
4,380 KB
testcase_29 AC 32 ms
4,380 KB
testcase_30 AC 5 ms
4,384 KB
testcase_31 AC 22 ms
4,380 KB
testcase_32 AC 738 ms
5,556 KB
testcase_33 AC 366 ms
4,380 KB
testcase_34 AC 1,420 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 27 ms
4,380 KB
testcase_37 WA -
testcase_38 AC 2 ms
4,380 KB
testcase_39 WA -
testcase_40 AC 4 ms
4,380 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

type edge struct {
	to, c, t int
}

const inf = 1001001001001

func main() {
	sc.Split(bufio.ScanWords)
	N, C, V := getInt(), getInt(), getInt()
	s := getInts(V)
	t := getInts(V)
	y := getInts(V)
	m := getInts(V)
	node := make([][]edge, N)
	for i := 0; i < V; i++ {
		from := s[i] - 1
		to := t[i] - 1
		node[from] = append(node[from], edge{to, y[i], m[i]})
		node[to] = append(node[to], edge{from, y[i], m[i]})
	}

	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
	q := make([]int, 0)
	q = append(q, 0)
	for len(q) != 0 {
		n := q[0]
		q = q[1:]
		for _, e := range node[n] {
			for j := e.c; j <= C; j++ {
				if dp[e.to][j-e.c] > dp[n][j]+e.t {
					dp[e.to][j-e.c] = dp[n][j] + e.t
					q = append(q, e.to)
				}
			}
		}
	}
	// for i := 0; i < N; i++ {
	// 	out(dp[i])
	// }
	ans := inf
	for i := 0; i <= C; i++ {
		ans = min(ans, dp[N-1][i])
	}
	if ans == inf {
		out(-1)
		return
	}
	out(ans)
}
0