結果
| 問題 |
No.659 徘徊迷路
|
| コンテスト | |
| ユーザー |
brthyyjp
|
| 提出日時 | 2022-01-18 14:44:01 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,368 bytes |
| コンパイル時間 | 357 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 65,152 KB |
| 最終ジャッジ日時 | 2024-11-23 13:21:35 |
| 合計ジャッジ時間 | 2,051 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 5 |
| other | RE * 12 |
ソースコード
import numpy as np
#A**n
def mat_pow(A, n):
size = len(A)
res = np.eye(size, dtype=np.float)
while n > 0:
if n & 1 == 1:
res = res @ A
A = A @ A
n = n>>1
return res
import sys
import io, os
input = sys.stdin.readline
def main():
r, c, t = map(int, input().split())
sy, sx = map(int, input().split())
gy, gx = map(int, input().split())
B = []
for i in range(r):
temp = str(input().rstrip())
B.append(temp)
B = ''.join(B)
A = [[0]*(r*c) for i in range(r*c)]
A = np.array(A, dtype=np.float)
for y in range(r):
for x in range(c):
v = y*c+x
if B[v] == '#':
continue
p = 0
cand = []
for dy, dx in (-1, 0), (1, 0), (0, 1), (0, -1):
ny, nx = y+dy, x+dx
nv = ny*c+nx
if 0 <= ny < r and 0 <= nx < c and B[nv] != '#':
p += 1
cand.append(nv)
if p == 0:
A[v][v] = 1
continue
for nv in cand:
A[nv][v] += 1/p
#print(A)
sv = sy*c+sx
gv = gy*c+gx
X = [0]*(r*c)
X[sv] = 1
A = mat_pow(A, t)
ans = 0
for v in range(v):
ans += A[gv][v]*X[v]
print(ans)
if __name__ == '__main__':
main()
brthyyjp