結果

問題 No.2441 行列累乗
ユーザー mattu34mattu34
提出日時 2023-09-05 00:09:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 913 bytes
コンパイル時間 802 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 71,840 KB
最終ジャッジ日時 2023-09-05 00:09:21
合計ジャッジ時間 4,285 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
71,600 KB
testcase_01 AC 94 ms
71,480 KB
testcase_02 AC 99 ms
71,392 KB
testcase_03 AC 103 ms
71,660 KB
testcase_04 AC 100 ms
71,504 KB
testcase_05 AC 101 ms
71,828 KB
testcase_06 AC 97 ms
71,328 KB
testcase_07 AC 98 ms
71,500 KB
testcase_08 AC 98 ms
71,840 KB
testcase_09 AC 97 ms
71,324 KB
testcase_10 AC 100 ms
71,320 KB
testcase_11 AC 99 ms
71,500 KB
testcase_12 AC 95 ms
71,328 KB
testcase_13 AC 98 ms
71,312 KB
testcase_14 AC 96 ms
71,620 KB
testcase_15 AC 97 ms
71,508 KB
testcase_16 AC 99 ms
71,416 KB
testcase_17 AC 99 ms
71,496 KB
testcase_18 AC 100 ms
71,568 KB
testcase_19 AC 101 ms
71,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
import heapq
import bisect

INF = float("inf")
MOD = 998244353


# modなし
# A*B
def mat_mul(A, B):
    C = [[0] * len(B[0]) for i in range(len(A))]
    for i in range(len(A)):
        for k in range(len(B)):
            for j in range(len(B[0])):
                C[i][j] = C[i][j] + A[i][k] * B[k][j]
    return C


# A**n
def mat_pow(A, n):
    B = [[0] * len(A) for i in range(len(A))]
    for i in range(len(A)):
        B[i][i] = 1
    while n > 0:
        if n & 1 == 1:
            B = mat_mul(A, B)
        A = mat_mul(A, A)
        n = n >> 1
    return B


# フィボナッチ数列の例
# N=int(input())
# if N==0 or N==1:
#     print(1)
#     exit()
# mat=[[1,1],[1,0]]
# init=[[1],[1]]
# mat_=mat_pow(mat,N-1)
# print(mat_mul(mat_,init)[0][0])
M = [list(map(int, input().split())) for _ in range(2)]
# print(mat_pow(M, 3))
mat = mat_pow(M, 3)
for m in mat:
    print(*m)
0