結果
| 問題 |
No.1105 Many Triplets
|
| コンテスト | |
| ユーザー |
WSKR
|
| 提出日時 | 2020-09-23 16:17:43 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 525 ms / 2,000 ms |
| コード長 | 679 bytes |
| コンパイル時間 | 190 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 44,004 KB |
| 最終ジャッジ日時 | 2024-06-27 22:45:08 |
| 合計ジャッジ時間 | 16,089 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#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)
WSKR