結果

問題 No.1105 Many Triplets
コンテスト
ユーザー たい
提出日時 2026-07-05 12:04:31
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 540 ms / 2,000 ms
コード長 579 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 312 ms
コンパイル使用メモリ 21,536 KB
実行使用メモリ 35,096 KB
最終ジャッジ日時 2026-07-05 12:04:51
合計ジャッジ時間 16,822 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import numpy as np

def multiply_matrices(A, B, mod):
    return (A @ B) % mod

def power_matrix(A, n, mod):
    result = np.identity(len(A), dtype=int)
    while n > 0:
        if n % 2 == 1:
            result = multiply_matrices(result, A, mod)
        A = multiply_matrices(A, A, mod)
        n //= 2
    return result

N = int(input())
a, b, c = map(int, input().split())
A = np.array([[1, -1, 0], [0, 1, -1], [-1, 0, 1]])
A_cube = power_matrix(A, N - 1, 10**9 + 7)
ans = multiply_matrices(A_cube, np.array([[a], [b], [c]]), 10**9 + 7)
print(ans[0][0], ans[1][0], ans[2][0])
0