結果

問題 No.1105 Many Triplets
ユーザー 双六双六
提出日時 2020-07-21 21:06:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 822 bytes
コンパイル時間 125 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 29,760 KB
最終ジャッジ日時 2023-08-29 22:26:55
合計ジャッジ時間 7,240 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
29,620 KB
testcase_01 AC 124 ms
29,560 KB
testcase_02 AC 127 ms
29,660 KB
testcase_03 AC 126 ms
29,736 KB
testcase_04 AC 131 ms
29,652 KB
testcase_05 AC 129 ms
29,556 KB
testcase_06 AC 133 ms
29,720 KB
testcase_07 AC 133 ms
29,592 KB
testcase_08 AC 131 ms
29,540 KB
testcase_09 AC 131 ms
29,596 KB
testcase_10 AC 131 ms
29,540 KB
testcase_11 AC 131 ms
29,604 KB
testcase_12 AC 132 ms
29,596 KB
testcase_13 AC 131 ms
29,588 KB
testcase_14 AC 133 ms
29,736 KB
testcase_15 AC 130 ms
29,608 KB
testcase_16 AC 130 ms
29,584 KB
testcase_17 AC 130 ms
29,760 KB
testcase_18 AC 135 ms
29,608 KB
testcase_19 AC 131 ms
29,704 KB
testcase_20 AC 128 ms
29,556 KB
testcase_21 AC 131 ms
29,620 KB
testcase_22 AC 132 ms
29,524 KB
testcase_23 AC 132 ms
29,656 KB
testcase_24 AC 131 ms
29,708 KB
testcase_25 AC 133 ms
29,716 KB
testcase_26 AC 133 ms
29,668 KB
testcase_27 AC 132 ms
29,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0