結果

問題 No.659 徘徊迷路
ユーザー mkawa2mkawa2
提出日時 2020-08-07 07:52:23
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,773 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 81,764 KB
実行使用メモリ 83,048 KB
最終ジャッジ日時 2023-10-23 21:27:04
合計ジャッジ時間 19,799 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
76,084 KB
testcase_01 AC 552 ms
77,628 KB
testcase_02 AC 85 ms
75,616 KB
testcase_03 AC 36 ms
53,444 KB
testcase_04 AC 745 ms
78,796 KB
testcase_05 AC 126 ms
76,008 KB
testcase_06 AC 130 ms
75,984 KB
testcase_07 AC 90 ms
75,608 KB
testcase_08 AC 878 ms
78,432 KB
testcase_09 AC 1,880 ms
81,820 KB
testcase_10 TLE -
testcase_11 TLE -
testcase_12 AC 491 ms
77,092 KB
testcase_13 AC 1,916 ms
81,884 KB
testcase_14 AC 1,881 ms
81,884 KB
testcase_15 TLE -
testcase_16 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def dot(aa,bb):
    return [[sum(a*b for a,b in zip(row,col)) for col in zip(*bb)] for row in aa]

def solve(t):
    pp = [[0] * w for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if aa[i][j]: continue
            for di, dj in dij:
                ni, nj = di + i, dj + j
                if ni < 0 or nj < 0 or ni >= h or nj >= w: continue
                pp[i][j] += 1 - aa[ni][nj]

    if pp[si][sj] == 0:
        print(1)
        exit()

    bb = [[0] * h * w for _ in range(h * w)]
    for i in range(h):
        for j in range(w):
            for di, dj in dij:
                ni, nj = di + i, dj + j
                if ni < 0 or nj < 0 or ni >= h or nj >= w: continue
                if pp[ni][nj]: bb[ni * w + nj][i * w + j] = 1 / pp[ni][nj]

    cc = [[0] * h * w for _ in range(h * w)]
    for i in range(h * w): cc[i][i] = 1
    while t:
        if t & 1:
            cc = dot(cc, bb)
        bb = dot(bb, bb)
        t >>= 1

    ans = [[0] * h * w]
    ans[0][si * w + sj] = 1
    ans = dot(ans, cc)
    print(ans[0][gi * w + gj])

h,w,t=MI()
si,sj=MI()
gi,gj=MI()
aa=[[c=="#" for c in SI()] for _ in range(h)]

solve(t)
0