結果

問題 No.659 徘徊迷路
ユーザー maspy
提出日時 2020-03-07 02:21:13
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 491 ms / 2,000 ms
コード長 814 bytes
コンパイル時間 190 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 45,012 KB
最終ジャッジ日時 2024-10-14 11:05:32
合計ジャッジ時間 9,788 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

# %%
R, C, T = map(int, readline().split())
Sy, Sx = map(int, readline().split())
Gy, Gx = map(int, readline().split())
B = ''.join(read().decode().split())

# %%
N = R * C
graph = [[] for _ in range(N)]
mat = np.zeros((N,N))
for i in range(N):
    if B[i] == '#':
        continue
    deg = 0
    for dx in [1, -1, -C, C]:
        if B[i + dx] == '.':
            deg += 1
    if deg == 0:
        mat[i, i] = 1.0
    else:
        p = 1 / deg
        for dx in [1, -1, -C, C]:
            if B[i + dx] == '.':
                mat[i, i + dx] = 1 / deg
        


# %%
A = np.linalg.matrix_power(mat, T)
S = Sy * C + Sx
G = Gy * C + Gx
print(A[S,G])
0