結果
問題 | No.859 路線A、路線B、路線C |
ユーザー | ccppjsrb |
提出日時 | 2020-09-15 11:39:17 |
言語 | Go (1.22.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,679 bytes |
コンパイル時間 | 13,463 ms |
コンパイル使用メモリ | 237,848 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-22 01:40:52 |
合計ジャッジ時間 | 12,488 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,812 KB |
testcase_02 | AC | 1 ms
6,812 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | WA | - |
testcase_07 | AC | 1 ms
6,944 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | WA | - |
testcase_13 | AC | 1 ms
6,944 KB |
testcase_14 | AC | 1 ms
6,944 KB |
ソースコード
package main import ( "bufio" "fmt" "math" "os" "strconv" ) func configure(scanner *bufio.Scanner) { scanner.Split(bufio.ScanWords) scanner.Buffer(make([]byte, 1000005), 1000005) } func getNextString(scanner *bufio.Scanner) string { scanned := scanner.Scan() if !scanned { panic("scan failed") } 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 getNextFloat64(scanner *bufio.Scanner) float64 { i, _ := strconv.ParseFloat(getNextString(scanner), 64) return i } func main() { fp := os.Stdin wfp := os.Stdout extra := 0 if os.Getenv("I") == "IronMan" { fp, _ = os.Open(os.Getenv("END_GAME")) extra = 100 } scanner := bufio.NewScanner(fp) configure(scanner) writer := bufio.NewWriter(wfp) defer func() { r := recover() if r != nil { fmt.Fprintln(writer, r) } writer.Flush() }() solve(scanner, writer) for i := 0; i < extra; i++ { fmt.Fprintln(writer, "-----------------------------------") solve(scanner, writer) } } func solve(scanner *bufio.Scanner, writer *bufio.Writer) { x := getNextInt(scanner) y := getNextInt(scanner) z := getNextInt(scanner) s0 := getNextString(scanner) t0 := getNextInt(scanner) s1 := getNextString(scanner) t1 := getNextInt(scanner) fw := makeGrid(4, 4) for i := 0; i < 4; i++ { for j := 0; j < 4; j++ { if i == j { continue } fw[i][j] = math.MaxInt32 } } if s0 == s1 { fw[0][1] = abs(t0-t1) << 1 fw[1][0] = abs(t0-t1) << 1 } fw[0][2] = t0<<1 - 1 fw[2][0] = t0<<1 - 1 fw[1][2] = t1<<1 - 1 fw[2][1] = t1<<1 - 1 fw[2][3] = min(x, min(y, z))<<1 + 1 fw[3][2] = min(x, min(y, z))<<1 + 1 switch s0 { case "A": fw[0][3] = (x-t0)<<1 + 1 fw[3][0] = (x-t0)<<1 + 1 fw[1][3] = (x-t1)<<1 + 1 fw[3][1] = (x-t1)<<1 + 1 case "B": fw[0][3] = (y-t0)<<1 + 1 fw[3][0] = (y-t0)<<1 + 1 fw[1][3] = (y-t1)<<1 + 1 fw[3][1] = (y-t1)<<1 + 1 case "C": fw[0][3] = (z-t0)<<1 + 1 fw[3][0] = (z-t0)<<1 + 1 fw[1][3] = (y-t1)<<1 + 1 fw[3][1] = (y-t1)<<1 + 1 } for k := 0; k < 4; k++ { for i := 0; i < 4; i++ { for j := 0; j < 4; j++ { if fw[i][j]-fw[i][k] > fw[k][j] { fw[i][j] = fw[i][k] + fw[k][j] } } } } fmt.Fprintln(writer, fw[0][1]>>1) } func makeGrid(h, w int) [][]int { index := make([][]int, h, h) data := make([]int, h*w, h*w) for i := 0; i < h; i++ { index[i] = data[i*w : (i+1)*w] } return index } func abs(a int) int { if a < 0 { return -a } return a } func min(a, b int) int { if a < b { return a } return b }