結果

問題 No.2441 行列累乗
ユーザー mattu34mattu34
提出日時 2023-09-05 00:08:02
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 893 bytes
コンパイル時間 709 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 71,720 KB
最終ジャッジ日時 2023-09-05 00:08:06
合計ジャッジ時間 3,544 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,336 KB
testcase_01 AC 95 ms
71,516 KB
testcase_02 AC 96 ms
71,580 KB
testcase_03 AC 94 ms
71,508 KB
testcase_04 AC 94 ms
71,264 KB
testcase_05 AC 94 ms
71,252 KB
testcase_06 AC 93 ms
71,516 KB
testcase_07 AC 93 ms
71,156 KB
testcase_08 AC 122 ms
71,432 KB
testcase_09 AC 95 ms
71,132 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

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))
for m in M:
    print(*m)

0