結果

問題 No.659 徘徊迷路
ユーザー wajima_wataruwajima_wataru
提出日時 2018-03-05 22:23:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,405 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 10,880 KB
実行使用メモリ 12,852 KB
最終ジャッジ日時 2023-10-11 20:34:23
合計ジャッジ時間 8,009 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,236 KB
testcase_01 AC 21 ms
8,084 KB
testcase_02 AC 131 ms
8,056 KB
testcase_03 AC 79 ms
8,108 KB
testcase_04 AC 792 ms
8,108 KB
testcase_05 AC 16 ms
8,088 KB
testcase_06 AC 16 ms
8,084 KB
testcase_07 AC 17 ms
8,072 KB
testcase_08 AC 41 ms
7,988 KB
testcase_09 AC 1,202 ms
8,132 KB
testcase_10 AC 1,815 ms
8,132 KB
testcase_11 TLE -
testcase_12 AC 17 ms
8,056 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

R, C, T = map(int, input().split())
sy, sx = map(int, input().split())
gy, gx = map(int, input().split())

B = []
E = []
for i in range(R):
    s = input()
    t = []
    for j, c in enumerate(s):
        t.append(c)
        if c == '.':
            E.append(i * C + j)
    B.append(t)

N = [False for _ in range(R * C)]
for i in range(1, R - 1):
    for j in range(1, C - 1):
        if i * C + j in E:
            t = []
            if B[i - 1][j] == '.':
                t.append([(i - 1) * C + j, 0])
            if B[i + 1][j] == '.':
                t.append([(i + 1) * C + j, 0])
            if B[i][j - 1] == '.':
                t.append([i * C + (j - 1), 0])
            if B[i][j + 1] == '.':
                t.append([i * C + (j + 1), 0])
            if len(t) == 0:
                t.append([i * C + j, 0])
            for p in t:
                p[1] = 1 / len(t)
            N[i * C + j] = t

P1 = [0 for _ in range(R * C)]
P2 = [0 for _ in range(R * C)]
P1[sy * C + sx] = 1
if T > 50000:
    T = 50000 if T % 2 == 0 else 50001
for i in range(T):
    if i % 2 == 0:
        for e in E:
            for t in N[e]:
                P2[t[0]] += P1[e] * t[1]
        P1 = [0 for _ in range(R * C)]
    else:
        for e in E:
            for t in N[e]:
                P1[t[0]] += P2[e] * t[1]
        P2 = [0 for _ in range(R * C)] 

print(P1[gy * C + gx] if T % 2 == 0 else P2[gy * C + gx])
0