結果

問題 No.659 徘徊迷路
ユーザー wajima_wataruwajima_wataru
提出日時 2018-03-05 22:23:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 562 ms / 2,000 ms
コード長 1,405 bytes
コンパイル時間 98 ms
コンパイル使用メモリ 10,936 KB
実行使用メモリ 8,176 KB
最終ジャッジ日時 2023-10-11 20:33:58
合計ジャッジ時間 4,799 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,052 KB
testcase_01 AC 24 ms
8,076 KB
testcase_02 AC 42 ms
8,140 KB
testcase_03 AC 31 ms
8,044 KB
testcase_04 AC 176 ms
8,112 KB
testcase_05 AC 16 ms
8,060 KB
testcase_06 AC 17 ms
8,108 KB
testcase_07 AC 17 ms
8,136 KB
testcase_08 AC 41 ms
8,140 KB
testcase_09 AC 263 ms
7,992 KB
testcase_10 AC 372 ms
8,068 KB
testcase_11 AC 547 ms
8,124 KB
testcase_12 AC 18 ms
8,064 KB
testcase_13 AC 557 ms
8,176 KB
testcase_14 AC 559 ms
7,988 KB
testcase_15 AC 561 ms
7,992 KB
testcase_16 AC 562 ms
8,116 KB
権限があれば一括ダウンロードができます

ソースコード

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 > 10000:
    T = 10000 if T % 2 == 0 else 10001
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