結果

問題 No.659 徘徊迷路
ユーザー rlangevinrlangevin
提出日時 2023-10-18 12:47:56
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,573 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 81,768 KB
実行使用メモリ 79,284 KB
最終ジャッジ日時 2023-10-18 12:48:09
合計ジャッジ時間 12,517 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
72,552 KB
testcase_01 AC 485 ms
76,492 KB
testcase_02 AC 60 ms
68,400 KB
testcase_03 AC 45 ms
59,800 KB
testcase_04 AC 412 ms
75,840 KB
testcase_05 AC 86 ms
75,672 KB
testcase_06 AC 84 ms
75,708 KB
testcase_07 AC 61 ms
68,432 KB
testcase_08 AC 726 ms
77,036 KB
testcase_09 AC 739 ms
77,036 KB
testcase_10 AC 1,029 ms
77,536 KB
testcase_11 AC 1,185 ms
77,556 KB
testcase_12 AC 383 ms
76,360 KB
testcase_13 AC 777 ms
76,960 KB
testcase_14 AC 1,708 ms
78,772 KB
testcase_15 TLE -
testcase_16 AC 1,232 ms
77,556 KB
権限があれば一括ダウンロードができます

ソースコード

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
         
    pre = Mat[f(gx, gy) * N + f(sx, sy)]
    while M:
        if M & 1:
            Mat = Matprod(Mat, A, N)
            nex = Mat[f(gx, gy) * N + f(sx, sy)]
            if abs(pre - nex) < 1e-7 and nex > 1e-7:
                return Mat
            pre = nex
        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.extend(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):
        v = f(i,j)
        if B[v] == "#":
            continue
        cnt = 0
        for k in range(4):
            x = i + dx[k]
            y = j + dy[k]
            if B[f(x,y)] == "#":
                continue
            cnt += 1
        if cnt == 0:
            M[v * N + v] = 1
        else:
            for k in range(4):
                x = i + dx[k]
                y = j + dy[k]
                if B[f(x,y)] == "#":
                    continue
                M[f(x,y) * N + v] += 1 / cnt

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

0