結果
| 問題 |
No.659 徘徊迷路
|
| コンテスト | |
| ユーザー |
mkawa2
|
| 提出日時 | 2020-08-07 07:57:05 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 528 ms / 2,000 ms |
| コード長 | 1,756 bytes |
| コンパイル時間 | 97 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 46,948 KB |
| 最終ジャッジ日時 | 2024-09-22 15:05:58 |
| 合計ジャッジ時間 | 11,260 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 12 |
ソースコード
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)]
import numpy as np
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 = np.zeros((h*w,h*w),dtype="f8")
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 = np.eye(h*w,dtype="f8")
while t:
if t & 1:
cc = np.dot(cc, bb)
bb = np.dot(bb, bb)
t >>= 1
ans = np.zeros((1,h*w),dtype="f8")
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)
mkawa2