結果

問題 No.1105 Many Triplets
ユーザー 👑 rin204rin204
提出日時 2022-07-06 07:43:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 681 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 76,024 KB
最終ジャッジ日時 2023-08-22 23:18:18
合計ジャッジ時間 3,964 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,432 KB
testcase_01 AC 71 ms
71,484 KB
testcase_02 AC 67 ms
71,408 KB
testcase_03 AC 68 ms
71,000 KB
testcase_04 AC 71 ms
71,196 KB
testcase_05 AC 68 ms
71,196 KB
testcase_06 AC 69 ms
71,168 KB
testcase_07 AC 68 ms
71,224 KB
testcase_08 AC 71 ms
71,408 KB
testcase_09 AC 66 ms
71,472 KB
testcase_10 AC 73 ms
75,916 KB
testcase_11 AC 75 ms
75,980 KB
testcase_12 AC 72 ms
75,876 KB
testcase_13 AC 70 ms
75,732 KB
testcase_14 AC 72 ms
75,780 KB
testcase_15 AC 73 ms
75,876 KB
testcase_16 AC 74 ms
75,884 KB
testcase_17 AC 75 ms
75,872 KB
testcase_18 AC 72 ms
76,024 KB
testcase_19 AC 73 ms
75,912 KB
testcase_20 AC 68 ms
71,408 KB
testcase_21 AC 72 ms
71,460 KB
testcase_22 AC 69 ms
71,224 KB
testcase_23 AC 69 ms
71,444 KB
testcase_24 AC 68 ms
71,164 KB
testcase_25 AC 69 ms
71,296 KB
testcase_26 AC 68 ms
71,496 KB
testcase_27 AC 70 ms
71,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7

def matpow(A, B, w):
    l = len(A)
    while w:
        if w & 1:
            C = [0] * l
            for i in range(l):
                for j in range(l):
                    C[i] += A[i][j] * B[j]
                    C[i] %= MOD
            B = C
        C = [[0] * l for _ in range(l)]
        for i in range(l):
            for j in range(l):
                for k in range(l):
                    C[i][j] += A[i][k] * A[k][j]
                    C[i][j] %= MOD
        A = C
        w >>= 1
    return B

n = int(input())
a, b, c = map(int, input().split())
B = [a, b, c]
A = [[1, -1, 0],
     [0, 1, -1],
     [-1, 0, 1]]
B = matpow(A, B, n - 1)
print(*B)
0