結果
問題 | No.659 徘徊迷路 |
ユーザー | ccppjsrb |
提出日時 | 2020-06-07 18:16:24 |
言語 | Go (1.22.1) |
結果 |
AC
|
実行時間 | 23 ms / 2,000 ms |
コード長 | 2,947 bytes |
コンパイル時間 | 13,768 ms |
コンパイル使用メモリ | 222,860 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-06 07:15:02 |
合計ジャッジ時間 | 14,278 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 4 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 3 ms
6,940 KB |
testcase_09 | AC | 6 ms
6,940 KB |
testcase_10 | AC | 12 ms
6,940 KB |
testcase_11 | AC | 23 ms
6,944 KB |
testcase_12 | AC | 3 ms
6,944 KB |
testcase_13 | AC | 23 ms
6,944 KB |
testcase_14 | AC | 23 ms
6,940 KB |
testcase_15 | AC | 22 ms
6,944 KB |
testcase_16 | AC | 23 ms
6,940 KB |
ソースコード
package main import ( "bufio" "fmt" "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) { r := getNextInt(scanner) c := getNextInt(scanner) t := getNextInt(scanner) sy := getNextInt(scanner) sx := getNextInt(scanner) gy := getNextInt(scanner) gx := getNextInt(scanner) bb := make([][]int, r) for i := 0; i < r; i++ { bb[i] = make([]int, c) } index := 0 for i := 0; i < r; i++ { b := getNextString(scanner) for j := 0; j < c; j++ { if b[j] == '#' { bb[i][j] = -1 continue } bb[i][j] = index index++ } } if index == 1 { fmt.Fprintln(writer, 1) return } ff := makeGrid(1, index) dbl := makeGrid(index, index) ff[0][bb[sy][sx]] = 1 dy := [4]int{-1, 0, 0, 1} dx := [4]int{0, -1, 1, 0} for i := 1; i < r-1; i++ { for j := 1; j < c-1; j++ { if bb[i][j] == -1 { continue } s := 0 for k := 0; k < 4; k++ { y := i + dy[k] x := j + dx[k] if bb[y][x] == -1 { continue } s++ } for k := 0; k < 4; k++ { y := i + dy[k] x := j + dx[k] if bb[y][x] == -1 { continue } dbl[bb[i][j]][bb[y][x]] = 1.0 / float64(s) } } } for t > 0 { if t%2 == 1 { ff = mul(ff, dbl) } dbl = mul(dbl, dbl) t >>= 1 } fmt.Fprintln(writer, ff[0][bb[gy][gx]]) } func dump(a [][]float64) { for i := 0; i < len(a); i++ { fmt.Printf("%v\n", a[i]) } } func mul(dbl, dbl2 [][]float64) [][]float64 { r := len(dbl) c := len(dbl[0]) c2 := len(dbl2[0]) result := makeGrid(r, c2) for i := 0; i < r; i++ { for j := 0; j < c2; j++ { for k := 0; k < c; k++ { result[i][j] += dbl[i][k] * dbl2[k][j] } } } return result } func makeGrid(h, w int) [][]float64 { index := make([][]float64, h, h) data := make([]float64, h*w, h*w) for i := 0; i < h; i++ { index[i] = data[i*w : (i+1)*w] } return index }