結果
問題 | No.659 徘徊迷路 |
ユーザー | H3PO4 |
提出日時 | 2020-11-06 08:52:12 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 141 ms / 2,000 ms |
コード長 | 877 bytes |
コンパイル時間 | 109 ms |
コンパイル使用メモリ | 10,956 KB |
実行使用メモリ | 32,232 KB |
最終ジャッジ日時 | 2023-09-29 17:38:57 |
合計ジャッジ時間 | 6,725 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 131 ms
29,872 KB |
testcase_01 | AC | 132 ms
30,220 KB |
testcase_02 | AC | 133 ms
31,500 KB |
testcase_03 | AC | 133 ms
29,684 KB |
testcase_04 | AC | 134 ms
30,036 KB |
testcase_05 | AC | 129 ms
29,908 KB |
testcase_06 | AC | 130 ms
30,032 KB |
testcase_07 | AC | 130 ms
29,984 KB |
testcase_08 | AC | 130 ms
32,060 KB |
testcase_09 | AC | 133 ms
30,300 KB |
testcase_10 | AC | 141 ms
32,092 KB |
testcase_11 | AC | 132 ms
30,236 KB |
testcase_12 | AC | 132 ms
30,192 KB |
testcase_13 | AC | 137 ms
32,124 KB |
testcase_14 | AC | 135 ms
30,452 KB |
testcase_15 | AC | 136 ms
32,020 KB |
testcase_16 | AC | 136 ms
32,232 KB |
ソースコード
import numpy as np R, C, T = map(int, input().split()) Sy, Sx = map(int, input().split()) Gy, Gx = map(int, input().split()) B = [input() for _ in range(R)] grid2int = lambda y, x: y * C + x matr = [[0] * (R * C) for _ in range(R * C)] for y in range(1, R - 1): for x in range(1, C - 1): if B[y][x] == '#': continue coor = grid2int(y, x) movable = [] for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)): ydy, xdx = y + dy, x + dx if B[ydy][xdx] == '.': movable.append(grid2int(ydy, xdx)) if not movable: matr[coor][coor] = 1 continue l = len(movable) for p in movable: matr[coor][p] = 1 / l matr = np.array(matr) X = np.zeros(R * C) X[grid2int(Sy, Sx)] = 1 Y = X @ np.linalg.matrix_power(matr, T) print(Y[grid2int(Gy, Gx)])