結果

問題 No.1105 Many Triplets
ユーザー anagohirameanagohirame
提出日時 2020-07-03 22:53:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 705 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 81,772 KB
実行使用メモリ 61,528 KB
最終ジャッジ日時 2023-10-17 05:55:24
合計ジャッジ時間 2,901 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,508 KB
testcase_01 AC 38 ms
53,508 KB
testcase_02 AC 38 ms
53,508 KB
testcase_03 AC 38 ms
53,508 KB
testcase_04 AC 38 ms
53,508 KB
testcase_05 AC 39 ms
53,508 KB
testcase_06 AC 38 ms
53,508 KB
testcase_07 AC 38 ms
53,508 KB
testcase_08 AC 39 ms
53,508 KB
testcase_09 AC 39 ms
53,508 KB
testcase_10 AC 48 ms
61,528 KB
testcase_11 AC 49 ms
61,528 KB
testcase_12 AC 48 ms
61,528 KB
testcase_13 AC 48 ms
61,528 KB
testcase_14 AC 48 ms
61,528 KB
testcase_15 AC 47 ms
61,528 KB
testcase_16 AC 48 ms
61,528 KB
testcase_17 AC 48 ms
61,528 KB
testcase_18 AC 48 ms
61,528 KB
testcase_19 AC 48 ms
61,528 KB
testcase_20 AC 38 ms
53,508 KB
testcase_21 AC 37 ms
53,508 KB
testcase_22 AC 38 ms
53,508 KB
testcase_23 AC 37 ms
53,508 KB
testcase_24 AC 37 ms
53,508 KB
testcase_25 AC 37 ms
53,508 KB
testcase_26 AC 37 ms
53,508 KB
testcase_27 AC 37 ms
53,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10**9+7
def mat_dot(one, two, mod):
	return [[sum([(one[i][k]*two[k][j])%mod for k in range(max(len(two), len(one[0])))])%mod for j in range(len(two[0]))] for i in range(len(one))]

def mat_pow(mat, exp, mod):
	size = len(mat)
	res = [[0 for _ in range(size)] for _ in range(size)]
	for i in range(size):
		res[i][i] = 1
	cnt = 0
	while (1<<cnt) <= exp:
		if (exp>>cnt)&1:
			res = mat_dot(res, mat, mod)
		mat = mat_dot(mat, mat, mod)
		cnt += 1
	return res

mat = [[1, MOD-1, 0], [0, 1, MOD-1], [MOD-1, 0, 1]]
res = mat_pow(mat, int(input())-1, MOD)
x = list(map(int, input().split()))
ans = [0, 0, 0]
for i in range(3):
	for j in range(3):
		ans[i] += x[j] * res[i][j]
		ans[i] %= MOD
print(*ans)
0