結果
問題 | No.1 道のショートカット |
ユーザー | ccppjsrb |
提出日時 | 2020-06-03 20:23:12 |
言語 | Go (1.22.1) |
結果 |
AC
|
実行時間 | 54 ms / 5,000 ms |
コード長 | 3,538 bytes |
コンパイル時間 | 16,383 ms |
コンパイル使用メモリ | 221,564 KB |
実行使用メモリ | 10,240 KB |
最終ジャッジ日時 | 2024-07-20 16:49:00 |
合計ジャッジ時間 | 13,365 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 4 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 4 ms
5,376 KB |
testcase_11 | AC | 17 ms
5,376 KB |
testcase_12 | AC | 24 ms
5,376 KB |
testcase_13 | AC | 20 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 1 ms
5,376 KB |
testcase_18 | AC | 1 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 4 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 1 ms
5,376 KB |
testcase_23 | AC | 54 ms
10,240 KB |
testcase_24 | AC | 50 ms
9,088 KB |
testcase_25 | AC | 8 ms
5,376 KB |
testcase_26 | AC | 4 ms
5,376 KB |
testcase_27 | AC | 38 ms
7,168 KB |
testcase_28 | AC | 1 ms
5,376 KB |
testcase_29 | AC | 6 ms
5,376 KB |
testcase_30 | AC | 2 ms
5,376 KB |
testcase_31 | AC | 6 ms
5,376 KB |
testcase_32 | AC | 7 ms
5,376 KB |
testcase_33 | AC | 3 ms
5,376 KB |
testcase_34 | AC | 31 ms
5,632 KB |
testcase_35 | AC | 2 ms
5,376 KB |
testcase_36 | AC | 3 ms
5,376 KB |
testcase_37 | AC | 2 ms
5,376 KB |
testcase_38 | AC | 1 ms
5,376 KB |
testcase_39 | AC | 2 ms
5,376 KB |
testcase_40 | AC | 1 ms
5,376 KB |
testcase_41 | AC | 1 ms
5,376 KB |
testcase_42 | AC | 1 ms
5,376 KB |
testcase_43 | AC | 2 ms
5,376 KB |
ソースコード
package main import ( "bufio" "container/heap" "fmt" "math" "os" "strconv" ) func getScanner(fp *os.File) *bufio.Scanner { scanner := bufio.NewScanner(fp) scanner.Split(bufio.ScanWords) scanner.Buffer(make([]byte, 1000005), 1000005) return scanner } func getNextString(scanner *bufio.Scanner) string { scanner.Scan() return scanner.Text() } func getNextInt(scanner *bufio.Scanner) int { i, _ := strconv.Atoi(getNextString(scanner)) return i } func getNextInt64(scanner *bufio.Scanner) int64 { i, _ := strconv.ParseInt(getNextString(scanner), 10, 64) return i } func getNextUint64(scanner *bufio.Scanner) uint64 { i, _ := strconv.ParseUint(getNextString(scanner), 10, 64) return i } func getNextFloat64(scanner *bufio.Scanner) float64 { i, _ := strconv.ParseFloat(getNextString(scanner), 64) return i } func main() { fp := os.Stdin wfp := os.Stdout cnt := 0 if os.Getenv("MASPY") == "ますピ" { fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT")) cnt = 3 } if os.Getenv("MASPYPY") == "ますピッピ" { wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10")) } scanner := getScanner(fp) writer := bufio.NewWriter(wfp) solve(scanner, writer) for i := 0; i < cnt; i++ { fmt.Fprintln(writer, "-----------------------------------") solve(scanner, writer) } writer.Flush() } func solve(scanner *bufio.Scanner, writer *bufio.Writer) { n := getNextInt(scanner) c := getNextInt(scanner) v := getNextInt(scanner) ss := make([]int, v) tt := make([]int, v) yy := make([]int, v) mm := make([]int, v) for i := 0; i < v; i++ { ss[i] = getNextInt(scanner) - 1 } for i := 0; i < v; i++ { tt[i] = getNextInt(scanner) - 1 } for i := 0; i < v; i++ { yy[i] = getNextInt(scanner) } for i := 0; i < v; i++ { mm[i] = getNextInt(scanner) } g := newGraph(n) for i := 0; i < v; i++ { g.appendEdge(ss[i], tt[i], i, yy[i], mm[i]) } for i := 0; i < n; i++ { g.v[i] = &vertex{ ym: make([]int, c+1), } for j := 0; j < c+1; j++ { g.v[i].ym[j] = -1 } } dd := &daikes{} heap.Init(dd) heap.Push(dd, newDaike(0, c, 0)) for dd.Len() > 0 { p := heap.Pop(dd).(daike) if g.v[p.i].ym[p.y] != -1 { continue } g.v[p.i].ym[p.y] = p.m for _, e := range g.e[p.i] { if p.y-e.y < 0 { continue } heap.Push(dd, newDaike(e.to, p.y-e.y, p.m+e.m)) } } ans := cint(math.MaxInt32) for i := 0; i < c+1; i++ { if g.v[n-1].ym[i] == -1 { continue } ans.min(cint(g.v[n-1].ym[i])) } if ans == cint(math.MaxInt32) { ans = -1 } fmt.Fprintln(writer, ans) } type cint int func (x *cint) min(y cint) *cint { if *x > y { *x = y } return x } func (x *cint) max(y cint) *cint { if *x < y { *x = y } return x } func newDaike(i, y, m int) daike { return daike{ i: i, y: y, m: m, } } type daike struct { i, y, m int } type daikes []daike func (h daikes) Len() int { return len(h) } func (h daikes) Less(i, j int) bool { return h[i].m < h[j].m } func (h daikes) Swap(i, j int) { h[i], h[j] = h[j], h[i] } func (h *daikes) Push(x interface{}) { *h = append(*h, x.(daike)) } func (h *daikes) Pop() interface{} { old := *h n := len(old) x := old[n-1] *h = old[0 : n-1] return x } type graph struct { v []*vertex e [][]*edge } func newGraph(n int) *graph { return &graph{ v: make([]*vertex, n), e: make([][]*edge, n), } } func (g *graph) appendEdge(from, to, id, y, m int) { g.e[from] = append(g.e[from], &edge{ to: to, id: id, y: y, m: m, }) } type vertex struct { ym []int } type edge struct { to, id, y, m int }