結果
問題 | No.659 徘徊迷路 |
ユーザー | convexineq |
提出日時 | 2021-03-12 09:12:14 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 172 ms / 2,000 ms |
コード長 | 1,163 bytes |
コンパイル時間 | 203 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 77,312 KB |
最終ジャッジ日時 | 2024-04-21 19:46:12 |
合計ジャッジ時間 | 3,150 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
60,928 KB |
testcase_01 | AC | 78 ms
72,704 KB |
testcase_02 | AC | 47 ms
60,416 KB |
testcase_03 | AC | 49 ms
59,648 KB |
testcase_04 | AC | 96 ms
75,776 KB |
testcase_05 | AC | 63 ms
74,112 KB |
testcase_06 | AC | 48 ms
62,080 KB |
testcase_07 | AC | 47 ms
59,648 KB |
testcase_08 | AC | 99 ms
75,520 KB |
testcase_09 | AC | 155 ms
77,312 KB |
testcase_10 | AC | 172 ms
77,056 KB |
testcase_11 | AC | 170 ms
77,056 KB |
testcase_12 | AC | 70 ms
68,864 KB |
testcase_13 | AC | 150 ms
77,312 KB |
testcase_14 | AC | 152 ms
77,056 KB |
testcase_15 | AC | 169 ms
77,056 KB |
testcase_16 | AC | 169 ms
77,312 KB |
ソースコード
def matmul(A,B): # A,B: 行列 res = [[0.0]*len(B[0]) for _ in range(len(A))] for i, resi in enumerate(res): for k, aik in enumerate(A[i]): for j,bkj in enumerate(B[k]): resi[j] += aik*bkj return res def matpow(A,p): #A^p mod M if p%2: return matmul(A, matpow(A,p-1)) elif p > 0: b = matpow(A,p//2) return matmul(b,b) else: return [[int(i==j)*1.0 for j in range(len(A))] for i in range(len(A))] h,w,t = map(int,input().split()) sx,sy = map(int,input().split()) gx,gy = map(int,input().split()) b = [input() for _ in range(h)] N = h*w A = [[0.0]*N for _ in range(N)] for i in range(1,h-1): for j in range(1,w-1): if b[i][j] == "#": continue v = i*w+j c = 0 for ni,nj in [(i-1,j),(i+1,j),(i,j-1),(i,j+1)]: if b[ni][nj] == ".": c += 1 if c==0: A[v][v] = 1.0 continue for ni,nj in [(i-1,j),(i+1,j),(i,j-1),(i,j+1)]: if b[ni][nj] == ".": A[v][ni*w+nj] = 1/c B = matpow(A,t) v = [0.0]*N v[sx*w+sy] = 1.0 v = matmul([v],B) print(v[0][gx*w+gy])