結果

問題 No.1105 Many Triplets
ユーザー H3PO4
提出日時 2021-10-31 14:17:42
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 472 ms / 2,000 ms
コード長 524 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 43,876 KB
最終ジャッジ日時 2024-10-08 20:40:09
合計ジャッジ時間 16,752 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

MOD = 10 ** 9 + 7


def pow_matrix_mod(x, n, mod=MOD):
    if not n:
        return np.eye(len(x), dtype=object)
    if n % 2 == 0:
        return pow_matrix_mod(x @ x % mod, n // 2) % mod
    else:
        return x @ pow_matrix_mod(x @ x % mod, (n - 1) // 2) % mod


N = int(input())
X = np.array(list(map(int, input().split())), dtype=object)
A = np.array([[1, 0, -1],
              [-1, 1, 0],
              [0, -1, 1]],
             dtype=object)
ans = X @ pow_matrix_mod(A, N - 1) % MOD
print(*ans)
0