結果

問題 No.1105 Many Triplets
ユーザー H3PO4H3PO4
提出日時 2021-10-31 14:17:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 517 ms / 2,000 ms
コード長 524 bytes
コンパイル時間 78 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 43,880 KB
最終ジャッジ日時 2024-04-17 07:06:45
合計ジャッジ時間 16,950 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 499 ms
43,744 KB
testcase_01 AC 508 ms
43,364 KB
testcase_02 AC 508 ms
43,592 KB
testcase_03 AC 501 ms
43,480 KB
testcase_04 AC 504 ms
43,616 KB
testcase_05 AC 496 ms
43,596 KB
testcase_06 AC 505 ms
43,360 KB
testcase_07 AC 504 ms
43,488 KB
testcase_08 AC 511 ms
43,616 KB
testcase_09 AC 494 ms
43,740 KB
testcase_10 AC 510 ms
43,744 KB
testcase_11 AC 517 ms
43,612 KB
testcase_12 AC 512 ms
43,360 KB
testcase_13 AC 504 ms
43,748 KB
testcase_14 AC 506 ms
43,612 KB
testcase_15 AC 500 ms
43,488 KB
testcase_16 AC 514 ms
43,880 KB
testcase_17 AC 506 ms
43,468 KB
testcase_18 AC 506 ms
43,592 KB
testcase_19 AC 501 ms
43,744 KB
testcase_20 AC 511 ms
43,752 KB
testcase_21 AC 496 ms
43,492 KB
testcase_22 AC 506 ms
43,612 KB
testcase_23 AC 507 ms
43,596 KB
testcase_24 AC 502 ms
43,616 KB
testcase_25 AC 502 ms
43,752 KB
testcase_26 AC 507 ms
43,480 KB
testcase_27 AC 504 ms
43,720 KB
権限があれば一括ダウンロードができます

ソースコード

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