結果
問題 | No.659 徘徊迷路 |
ユーザー | mkawa2 |
提出日時 | 2020-08-07 07:57:05 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 601 ms / 2,000 ms |
コード長 | 1,756 bytes |
コンパイル時間 | 96 ms |
コンパイル使用メモリ | 12,232 KB |
実行使用メモリ | 78,436 KB |
最終ジャッジ日時 | 2023-10-23 21:38:44 |
合計ジャッジ時間 | 12,088 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 601 ms
44,272 KB |
testcase_01 | AC | 458 ms
44,372 KB |
testcase_02 | AC | 453 ms
44,356 KB |
testcase_03 | AC | 455 ms
42,740 KB |
testcase_04 | AC | 458 ms
44,372 KB |
testcase_05 | AC | 456 ms
44,356 KB |
testcase_06 | AC | 458 ms
44,356 KB |
testcase_07 | AC | 452 ms
44,356 KB |
testcase_08 | AC | 459 ms
44,372 KB |
testcase_09 | AC | 461 ms
44,372 KB |
testcase_10 | AC | 459 ms
44,372 KB |
testcase_11 | AC | 473 ms
44,356 KB |
testcase_12 | AC | 457 ms
44,356 KB |
testcase_13 | AC | 461 ms
44,372 KB |
testcase_14 | AC | 459 ms
44,356 KB |
testcase_15 | AC | 464 ms
44,356 KB |
testcase_16 | AC | 459 ms
78,436 KB |
ソースコード
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)