結果
問題 | No.1105 Many Triplets |
ユーザー |
![]() |
提出日時 | 2020-07-21 21:06:57 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 519 ms / 2,000 ms |
コード長 | 822 bytes |
コンパイル時間 | 111 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 44,628 KB |
最終ジャッジ日時 | 2024-12-31 01:22:30 |
合計ジャッジ時間 | 16,672 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) import numpy as np mod = 10 ** 9 + 7 def getlist(): return list(map(int, input().split())) def matrixPow(A, n, N): #B:単位行列 演算の種類によって初期化方法を変える必要もある B = np.full((N, N), 0) for i in range(N): B[i, i] = 1 while n > 0: if n & 1 == 1: B = A @ B B = np.mod(B, mod) A = A @ A A = np.mod(A, mod) n = n >> 1 return B #処理内容 def main(): N = int(input()) A1, B1, C1 = getlist() start = np.array([[A1], [B1], [C1]]) mul = np.array([[1, -1, 0], [0, 1, -1], [-1, 0, 1]]) B = matrixPow(mul, N - 1, 3) # print(B) ans = B @ start ans = np.mod(ans, mod) # print(ans) anslist = [ans[0, 0], ans[1, 0], ans[2, 0]] print(*anslist) if __name__ == '__main__': main()