結果

問題 No.1105 Many Triplets
ユーザー rlangevinrlangevin
提出日時 2023-07-03 08:51:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 814 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 76,540 KB
最終ジャッジ日時 2023-09-24 05:43:09
合計ジャッジ時間 4,141 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
71,316 KB
testcase_01 AC 66 ms
71,176 KB
testcase_02 AC 65 ms
71,268 KB
testcase_03 AC 66 ms
71,336 KB
testcase_04 AC 68 ms
71,380 KB
testcase_05 AC 64 ms
71,160 KB
testcase_06 AC 65 ms
71,252 KB
testcase_07 AC 64 ms
70,988 KB
testcase_08 AC 66 ms
71,516 KB
testcase_09 AC 66 ms
70,984 KB
testcase_10 AC 78 ms
76,300 KB
testcase_11 AC 72 ms
76,320 KB
testcase_12 AC 71 ms
76,112 KB
testcase_13 AC 71 ms
76,540 KB
testcase_14 AC 69 ms
76,532 KB
testcase_15 AC 70 ms
76,308 KB
testcase_16 AC 71 ms
76,308 KB
testcase_17 AC 68 ms
76,372 KB
testcase_18 AC 70 ms
76,420 KB
testcase_19 AC 69 ms
76,372 KB
testcase_20 AC 63 ms
71,452 KB
testcase_21 AC 63 ms
71,440 KB
testcase_22 AC 63 ms
71,296 KB
testcase_23 AC 65 ms
71,312 KB
testcase_24 AC 62 ms
71,464 KB
testcase_25 AC 65 ms
71,608 KB
testcase_26 AC 67 ms
71,340 KB
testcase_27 AC 65 ms
71,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def Matprod(A, B, mod, N):
    temp = [0] * N*N
    for i in range(N):
        for j in range(N):
            ij = i * N + j
            for k in range(N):
                temp[ij] += A[i*N+k] * B[k*N+j]
                temp[ij] %= mod
    return temp

def Matpow_Linear(A, M, mod, N):
    Mat = [0] * N*N
    for i in range(N):
        Mat[i*N+i] = 1
         
    while M:
        if M & 1:
            Mat = Matprod(Mat, A, mod, N)
        A = Matprod(A, A, mod, N)
        M >>= 1
    return Mat  


N = int(input())
X = list(map(int, input().split()))

A = [1, -1, 0, 0, 1, -1, -1, 0, 1]
mod = 10 ** 9 + 7
A = Matpow_Linear(A, N - 1, mod, 3)
ans = [0] * 3
for i in range(3):
    for j in range(3):
        ans[i] += A[3 * i + j] * X[j]
        ans[i] %= mod

print(*ans)
0