結果

問題 No.1810 RGB Biscuits
ユーザー brthyyjpbrthyyjp
提出日時 2022-01-14 21:51:52
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 261 ms / 2,000 ms
コード長 1,412 bytes
コンパイル時間 875 ms
コンパイル使用メモリ 86,936 KB
実行使用メモリ 79,412 KB
最終ジャッジ日時 2023-08-12 19:12:32
合計ジャッジ時間 5,467 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,148 KB
testcase_01 AC 90 ms
76,228 KB
testcase_02 AC 82 ms
76,232 KB
testcase_03 AC 93 ms
76,228 KB
testcase_04 AC 95 ms
76,368 KB
testcase_05 AC 236 ms
78,460 KB
testcase_06 AC 261 ms
78,972 KB
testcase_07 AC 261 ms
78,484 KB
testcase_08 AC 247 ms
78,524 KB
testcase_09 AC 258 ms
79,412 KB
testcase_10 AC 209 ms
78,896 KB
testcase_11 AC 95 ms
76,492 KB
testcase_12 AC 105 ms
77,416 KB
testcase_13 AC 98 ms
76,328 KB
testcase_14 AC 146 ms
78,580 KB
testcase_15 AC 110 ms
77,552 KB
testcase_16 AC 126 ms
78,304 KB
testcase_17 AC 196 ms
78,344 KB
testcase_18 AC 202 ms
78,744 KB
testcase_19 AC 95 ms
76,292 KB
testcase_20 AC 86 ms
76,124 KB
testcase_21 AC 135 ms
77,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# A*B
def mat_mul(A, B, mod):
    C = [[0]*len(B[0]) for i in range(len(A))]
    for i in range(len(A)):
        for k in range(len(B)):
            for j in range(len(B[0])):
                C[i][j] = (C[i][j] + A[i][k]*B[k][j])%mod
    return C

#A**n
def mat_pow(A, n, mod):
    B = [[0]*len(A) for i in range(len(A))]
    for i in range(len(A)):
        B[i][i] = 1
    while n > 0:
        if n & 1 == 1:
            B = mat_mul(A, B, mod)
        A = mat_mul(A, A, mod)
        n = n>>1
    return B

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

mod = 10**9+7

def main():

    a, b = map(int, input().split())
    n = int(input())
    X0 = [1, 1, 0]
    X1 = [1, 1, a+b]
    for i in range(n):
        t = int(input())
        if t%2 == 0:
            t //= 2
            A = [[a, b, 0], [1, 0, 0], [0, 0, 0]]
            A = mat_pow(A, t, mod)
            ans = 0
            for i in range(3):
                for j in range(3):
                    ans += A[i][j]*X0[j]
                    ans %= mod
            print(ans)
        else:
            t //= 2
            A = [[0, 0, 1], [1, 0, 0], [b, 0, a]]
            A = mat_pow(A, t, mod)
            ans = 0
            for i in range(3):
                for j in range(3):
                    ans += A[i][j]*X1[j]
                    ans %= mod
            print(ans)
if __name__ == '__main__':
    main()
0