結果
問題 | No.2441 行列累乗 |
ユーザー |
|
提出日時 | 2023-10-04 16:03:06 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 529 ms / 2,000 ms |
コード長 | 692 bytes |
コンパイル時間 | 220 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 44,616 KB |
最終ジャッジ日時 | 2024-07-26 14:45:56 |
合計ジャッジ時間 | 12,055 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
import numpy as npdef dot(A1, A2, N):# N: 行列のサイズA = np.zeros((N, N), dtype=int)for i in range(N):for j in range(N):for k in range(N):A[i][j] = (A[i][j] + (A1[i][k] * A2[k][j]))return Adef pow_mat(A, K, N):# A: 累乗する行列, k: 累乗数, n: 行列AのサイズP = np.eye(N, dtype=int)while K:if K & 1:P = dot(P, A, N)A = dot(A, A, N)K >>= 1return Pa,b = map(int,input().split())c,d = map(int,input().split())mat = np.array([[a, b], [c, d]], dtype=int)ans_matrix = pow_mat(mat, 3, 2)for row in ans_matrix:print(" ".join(map(str, row)))