結果

問題 No.659 徘徊迷路
ユーザー convexineqconvexineq
提出日時 2021-03-12 09:11:24
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,163 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 77,312 KB
最終ジャッジ日時 2024-04-21 19:44:29
合計ジャッジ時間 2,811 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
60,800 KB
testcase_01 AC 75 ms
72,320 KB
testcase_02 AC 45 ms
60,672 KB
testcase_03 RE -
testcase_04 AC 92 ms
75,728 KB
testcase_05 AC 56 ms
74,112 KB
testcase_06 AC 49 ms
62,464 KB
testcase_07 AC 45 ms
60,032 KB
testcase_08 AC 95 ms
75,776 KB
testcase_09 AC 156 ms
77,192 KB
testcase_10 AC 170 ms
76,800 KB
testcase_11 AC 168 ms
77,184 KB
testcase_12 AC 69 ms
68,992 KB
testcase_13 AC 156 ms
77,184 KB
testcase_14 AC 156 ms
77,184 KB
testcase_15 AC 172 ms
77,184 KB
testcase_16 AC 172 ms
77,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def matmul(A,B): # A,B: 行列
    res = [[0.0]*len(B[0]) for _ in range(len(A))]
    for i, resi in enumerate(res):
        for k, aik in enumerate(A[i]):
            for j,bkj in enumerate(B[k]):
                resi[j] += aik*bkj
    return res

def matpow(A,p): #A^p mod M
    if p%2:
        return matmul(A, matpow(A,p-1))
    elif p > 0:
        b = matpow(A,p//2)
        return matmul(b,b)
    else:
        return [[int(i==j)*1.0 for j in range(len(A))] for i in range(len(A))]

h,w,t = map(int,input().split())
sx,sy = map(int,input().split())
gx,gy = map(int,input().split())
b = [input() for _ in range(h)]
N = h*w
A = [[0.0]*N for _ in range(N)]
for i in range(1,h-1):
    for j in range(1,w-1):
        if b[i][j] == "#": continue
        v = i*w+j
        c = 0
        for ni,nj in [(i-1,j),(i+1,j),(i,j-1),(i,j+1)]:
            if b[ni][nj] == ".":
                c += 1
        if c==0:
            b[v][v] = 1.0
            continue
        for ni,nj in [(i-1,j),(i+1,j),(i,j-1),(i,j+1)]:
            if b[ni][nj] == ".":
                A[v][ni*w+nj] = 1/c

B = matpow(A,t)
v = [0.0]*N
v[sx*w+sy] = 1.0
v = matmul([v],B)
print(v[0][gx*w+gy])
0