結果

問題 No.1105 Many Triplets
ユーザー roarisroaris
提出日時 2020-07-03 22:55:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 793 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 81,688 KB
実行使用メモリ 61,892 KB
最終ジャッジ日時 2023-10-17 05:58:45
合計ジャッジ時間 2,542 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

def mat_mul(A, B):
    C = [[0]*len(B[0]) for _ in range(len(A))]
    
    for i in range(len(A)):
        for j in range(len(B[0])):
            for k in range(len(A[0])):
                C[i][j] += A[i][k]*B[k][j]
                C[i][j] %= MOD
    
    return C

def mat_pow(A, n):
    res = [[0]*len(A) for _ in range(len(A))]
    
    for i in range(len(A)):
        res[i][i] = 1
    
    while n>0:
        if n&1:
            res = mat_mul(res, A)
        
        n >>= 1
        A = mat_mul(A, A)
    
    return res

N = int(input())
A, B, C = map(int, input().split())
MOD = 10**9+7
X = [[1, -1, 0], [0, 1, -1], [-1, 0, 1]]
a = [[A], [B], [C]]
res = mat_mul(mat_pow(X, N-1), a)
print(res[0][0], res[1][0], res[2][0])
0