結果

問題 No.1105 Many Triplets
ユーザー WSKRWSKR
提出日時 2020-09-23 16:17:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 679 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 10,852 KB
実行使用メモリ 29,708 KB
最終ジャッジ日時 2023-09-10 07:17:11
合計ジャッジ時間 7,646 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
29,644 KB
testcase_01 AC 134 ms
29,528 KB
testcase_02 AC 135 ms
29,668 KB
testcase_03 AC 134 ms
29,632 KB
testcase_04 AC 133 ms
29,652 KB
testcase_05 AC 138 ms
29,708 KB
testcase_06 AC 136 ms
29,504 KB
testcase_07 AC 134 ms
29,584 KB
testcase_08 AC 135 ms
29,512 KB
testcase_09 AC 136 ms
29,516 KB
testcase_10 AC 134 ms
29,524 KB
testcase_11 AC 134 ms
29,640 KB
testcase_12 AC 135 ms
29,532 KB
testcase_13 AC 135 ms
29,600 KB
testcase_14 AC 136 ms
29,544 KB
testcase_15 AC 135 ms
29,604 KB
testcase_16 AC 136 ms
29,588 KB
testcase_17 AC 135 ms
29,576 KB
testcase_18 AC 135 ms
29,468 KB
testcase_19 AC 133 ms
29,616 KB
testcase_20 AC 135 ms
29,572 KB
testcase_21 AC 140 ms
29,568 KB
testcase_22 AC 136 ms
29,684 KB
testcase_23 AC 136 ms
29,544 KB
testcase_24 AC 138 ms
29,568 KB
testcase_25 AC 137 ms
29,536 KB
testcase_26 AC 136 ms
29,604 KB
testcase_27 AC 134 ms
29,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#many tripets

import numpy as np


def matrix_power(A, N, mod):
    # returnA^N %mod in O(K**3 log N). (K is the size of A.)
    assert A.shape[0] == A.shape[1]
    K = A.shape[0]
    if N == 0:
        return np.eye(K, dtype=np.int64)
    else:
        if N % 2 == 0:
            mat = matrix_power(A, N//2, mod)
            return np.dot(mat, mat) % mod
        else:
            mat = matrix_power(A, N//2, mod)
            return np.dot(np.dot(mat, mat) % mod, A) % mod


mod = 10 ** 9 + 7
N = int(input())
X = list(map(int, input().split()))
A = np.array([[1, -1, 0], [0, 1, -1], [-1, 0, 1]])
res = np.dot(matrix_power(A, N-1, mod), np.array(X))
res %= mod

print(*res)

0