結果

問題 No.1105 Many Triplets
ユーザー convexineqconvexineq
提出日時 2021-05-10 04:54:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 677 bytes
コンパイル時間 1,067 ms
コンパイル使用メモリ 81,536 KB
実行使用メモリ 59,688 KB
最終ジャッジ日時 2023-10-19 12:44:59
合計ジャッジ時間 3,410 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

def matmul(A,B): # A,B: 行列
    res = [[0]*len(B[0]) for _ in [None]*len(A)]
    for i, resi in enumerate(res):
        for k, aik in enumerate(A[i]):
            for j,bkj in enumerate(B[k]):
                resi[j] += aik*bkj
                resi[j] %= MOD
    return res

def matpow(A,p): #A^p mod M
    if p%2:
        return matmul(A, matpow(A,p-1))
    elif p > 0:
        b = matpow(A,p//2)
        return matmul(b,b)
    else:
        return [[int(i==j) for j in range(len(A))] for i in range(len(A))]

MOD=10**9+7
n = int(input())
a,b,c = map(int,input().split())
A = [[1,-1,0],[0,1,-1],[-1,0,1]]
v = matmul(matpow(A,n-1),[[a],[b],[c]])
r = v[0]+v[1]+v[2]
print(*r)
0