結果
問題 | No.1 道のショートカット |
ユーザー | ccppjsrb |
提出日時 | 2020-06-03 20:10:47 |
言語 | Go (1.22.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,595 bytes |
コンパイル時間 | 14,639 ms |
コンパイル使用メモリ | 222,036 KB |
実行使用メモリ | 26,608 KB |
最終ジャッジ日時 | 2024-07-08 05:27:02 |
合計ジャッジ時間 | 11,420 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 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 | 22 ms
9,088 KB |
testcase_09 | AC | 17 ms
7,040 KB |
testcase_10 | AC | 11 ms
5,376 KB |
testcase_11 | AC | 19 ms
7,424 KB |
testcase_12 | AC | 41 ms
14,208 KB |
testcase_13 | AC | 40 ms
14,208 KB |
testcase_14 | AC | 3 ms
5,376 KB |
testcase_15 | RE | - |
testcase_16 | WA | - |
testcase_17 | RE | - |
testcase_18 | AC | 4 ms
5,376 KB |
testcase_19 | AC | 8 ms
5,376 KB |
testcase_20 | AC | 8 ms
5,376 KB |
testcase_21 | WA | - |
testcase_22 | AC | 7 ms
5,376 KB |
testcase_23 | AC | 94 ms
24,192 KB |
testcase_24 | AC | 115 ms
26,608 KB |
testcase_25 | AC | 28 ms
8,064 KB |
testcase_26 | AC | 21 ms
6,656 KB |
testcase_27 | AC | 46 ms
12,032 KB |
testcase_28 | RE | - |
testcase_29 | AC | 5 ms
5,376 KB |
testcase_30 | AC | 2 ms
5,376 KB |
testcase_31 | AC | 6 ms
5,376 KB |
testcase_32 | AC | 15 ms
6,016 KB |
testcase_33 | AC | 11 ms
5,376 KB |
testcase_34 | AC | 26 ms
9,344 KB |
testcase_35 | AC | 2 ms
5,376 KB |
testcase_36 | AC | 3 ms
5,376 KB |
testcase_37 | WA | - |
testcase_38 | AC | 1 ms
5,376 KB |
testcase_39 | WA | - |
testcase_40 | AC | 2 ms
5,376 KB |
testcase_41 | AC | 1 ms
5,376 KB |
testcase_42 | RE | - |
testcase_43 | RE | - |
ソースコード
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 = 2 } 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(v) for i := 0; i < v; i++ { g.v[i] = &vertex{ ym: make([]int, c+1), } for j := 0; j < c+1; j++ { g.v[i].ym[j] = -1 } g.appendEdge(ss[i], tt[i], i, yy[i], mm[i]) g.appendEdge(tt[i], ss[i], i, yy[i], mm[i]) } 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 } if g.v[e.to].ym[p.y-e.y] == -1 { heap.Push(dd, newDaike(e.to, p.y-e.y, p.m+e.m)) } } } ans := cint(math.MaxInt32) for i := 0; i < c; 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 }