結果

問題 No.659 徘徊迷路
ユーザー rlangevinrlangevin
提出日時 2023-10-18 12:37:08
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,368 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 81,760 KB
実行使用メモリ 79,280 KB
最終ジャッジ日時 2023-10-18 12:37:26
合計ジャッジ時間 17,773 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
72,516 KB
testcase_01 AC 463 ms
76,548 KB
testcase_02 AC 66 ms
68,364 KB
testcase_03 AC 44 ms
61,812 KB
testcase_04 AC 403 ms
75,804 KB
testcase_05 AC 86 ms
75,636 KB
testcase_06 AC 85 ms
75,672 KB
testcase_07 AC 61 ms
68,396 KB
testcase_08 AC 735 ms
76,924 KB
testcase_09 AC 1,680 ms
78,740 KB
testcase_10 AC 1,991 ms
79,264 KB
testcase_11 TLE -
testcase_12 AC 383 ms
76,328 KB
testcase_13 AC 1,711 ms
78,816 KB
testcase_14 AC 1,715 ms
78,812 KB
testcase_15 TLE -
testcase_16 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def Matprod(A, B, N):
    temp = [0] * N*N
    for i in range(N):
        for j in range(N):
            ij = i * N + j
            for k in range(N):
                temp[ij] += A[i*N+k] * B[k*N+j]
    return temp

def Matpow_Linear(A, M, N):
    Mat = [0] * N*N
    for i in range(N):
        Mat[i*N+i] = 1
         
    while M:
        if M & 1:
            Mat = Matprod(Mat, A, N)
        A = Matprod(A, A, N)
        M >>= 1
    return Mat  

H, W, T = map(int, input().split())
sx, sy = map(int, input().split())
gx, gy = map(int, input().split())
N = H * W
M = [0] * N * N
B = []
for i in range(H):
    B.append(list(input().rstrip()))

dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]

def f(h, w):
    return h * W + w

for i in range(H):
    for j in range(W):
        if B[i][j] == "#":
            continue
        cnt = 0
        for k in range(4):
            x = i + dx[k]
            y = j + dy[k]
            if B[x][y] == "#":
                continue
            cnt += 1
        if cnt == 0:
            M[f(i, j) * N + f(i, j)] = 1
        else:
            for k in range(4):
                x = i + dx[k]
                y = j + dy[k]
                if B[x][y] == "#":
                    continue
                M[f(x, y) * N + f(i, j)] += 1 / cnt

M = Matpow_Linear(M, T, N)
print(M[f(gx, gy) * N + f(sx, sy)])
0