結果

問題 No.1105 Many Triplets
ユーザー Kiri8128Kiri8128
提出日時 2020-07-03 22:24:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 594 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 11,916 KB
実行使用メモリ 10,128 KB
最終ジャッジ日時 2023-10-17 05:15:13
合計ジャッジ時間 2,805 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,100 KB
testcase_01 AC 28 ms
10,100 KB
testcase_02 AC 28 ms
10,100 KB
testcase_03 AC 27 ms
10,100 KB
testcase_04 AC 26 ms
10,100 KB
testcase_05 AC 28 ms
10,100 KB
testcase_06 AC 26 ms
10,100 KB
testcase_07 AC 28 ms
10,100 KB
testcase_08 AC 29 ms
10,100 KB
testcase_09 AC 27 ms
10,100 KB
testcase_10 AC 26 ms
10,128 KB
testcase_11 AC 26 ms
10,128 KB
testcase_12 AC 26 ms
10,128 KB
testcase_13 AC 29 ms
10,128 KB
testcase_14 AC 27 ms
10,128 KB
testcase_15 AC 26 ms
10,128 KB
testcase_16 AC 27 ms
10,128 KB
testcase_17 AC 28 ms
10,128 KB
testcase_18 AC 26 ms
10,128 KB
testcase_19 AC 26 ms
10,128 KB
testcase_20 AC 25 ms
10,092 KB
testcase_21 AC 25 ms
10,092 KB
testcase_22 AC 25 ms
10,092 KB
testcase_23 AC 24 ms
10,092 KB
testcase_24 AC 26 ms
10,092 KB
testcase_25 AC 24 ms
10,092 KB
testcase_26 AC 24 ms
10,092 KB
testcase_27 AC 24 ms
10,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def mmult(A, B):
    global mod
    n, m, l = len(A), len(B), len(B[0])
    ret = [[0]*l for _ in range(n)]
    for i in range(n):
        for j in range(m):
            for k in range(l):
                ret[i][k] = (ret[i][k]+A[i][j]*B[j][k])%mod
    return ret
def mpow(A, n):
    if n == 0: return [[1 if i==j else 0 for j in range(len(A))] for i in range(len(A))]
    return mmult(mpow(A, n-1), A) if n % 2 else mpow(mmult(A, A), n//2)

N = int(input())
A, B, C = map(int, input().split())

mod = 10**9+7
X = [[1,0,-1],[-1,1,0],[0,-1,1]]
V = [[A, B, C]]
print(*mmult(V, mpow(X, N - 1))[0])
0