結果

問題 No.1105 Many Triplets
ユーザー kariya1975kariya1975
提出日時 2020-07-18 13:03:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 975 bytes
コンパイル時間 81 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 8,484 KB
最終ジャッジ日時 2023-08-20 17:16:49
合計ジャッジ時間 1,720 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,404 KB
testcase_01 AC 18 ms
8,424 KB
testcase_02 AC 17 ms
8,324 KB
testcase_03 AC 17 ms
8,340 KB
testcase_04 AC 18 ms
8,340 KB
testcase_05 AC 17 ms
8,484 KB
testcase_06 AC 17 ms
8,332 KB
testcase_07 AC 17 ms
8,136 KB
testcase_08 AC 17 ms
8,344 KB
testcase_09 AC 17 ms
8,284 KB
testcase_10 AC 18 ms
8,396 KB
testcase_11 AC 17 ms
8,332 KB
testcase_12 AC 17 ms
8,416 KB
testcase_13 AC 18 ms
8,364 KB
testcase_14 AC 17 ms
8,320 KB
testcase_15 AC 17 ms
8,344 KB
testcase_16 AC 18 ms
8,448 KB
testcase_17 AC 18 ms
8,276 KB
testcase_18 AC 17 ms
8,280 KB
testcase_19 AC 17 ms
8,348 KB
testcase_20 AC 16 ms
8,324 KB
testcase_21 AC 17 ms
8,276 KB
testcase_22 AC 16 ms
8,280 KB
testcase_23 AC 16 ms
8,348 KB
testcase_24 AC 17 ms
8,340 KB
testcase_25 AC 17 ms
8,320 KB
testcase_26 AC 16 ms
8,344 KB
testcase_27 AC 17 ms
8,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

MOD = 10 ** 9 + 7

def square(A):
    ans = [[0,0,0], [0,0,0], [0,0,0]]
    for i in range(3):
        for j in range(3):
            for k in range(3):
                ans[i][j] += (A[i][k] * A[k][j]) % MOD
            ans[i][j] %= MOD
    return ans

def prod(A, B):
    ans = [[0,0,0], [0,0,0], [0,0,0]]
    for i in range(3):
        for j in range(3):
            for k in range(3):
                ans[i][j] += (A[i][k] * B[k][j]) % MOD
        ans[i][j] %= MOD
    return ans

M = [[1, -1, 0], [0, 1, -1], [-1, 0, 1]]
limit = 64
M2 = [M] * limit 
for i in range(1, limit):
    M2[i] = square(M2[i-1])

MM = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
for i in range(limit):
    if ((N - 1) >> i) % 2 == 1:
        MM = prod(MM, M2[i])

a = (MM[0][0] * A + MM[0][1] * B + MM[0][2] * C) % MOD
b = (MM[1][0] * A + MM[1][1] * B + MM[1][2] * C) % MOD 
c = (MM[2][0] * A + MM[2][1] * B + MM[2][2] * C) % MOD

print(a, b, c)
0