結果

問題 No.1810 RGB Biscuits
ユーザー brthyyjpbrthyyjp
提出日時 2022-01-14 21:51:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 200 ms / 2,000 ms
コード長 1,412 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 82,564 KB
実行使用メモリ 77,952 KB
最終ジャッジ日時 2024-04-30 14:16:57
合計ジャッジ時間 3,094 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,548 KB
testcase_01 AC 45 ms
62,004 KB
testcase_02 AC 39 ms
60,580 KB
testcase_03 AC 51 ms
68,280 KB
testcase_04 AC 52 ms
69,032 KB
testcase_05 AC 174 ms
77,156 KB
testcase_06 AC 200 ms
77,952 KB
testcase_07 AC 197 ms
77,580 KB
testcase_08 AC 200 ms
77,508 KB
testcase_09 AC 194 ms
77,768 KB
testcase_10 AC 157 ms
77,476 KB
testcase_11 AC 55 ms
70,108 KB
testcase_12 AC 63 ms
73,548 KB
testcase_13 AC 56 ms
71,624 KB
testcase_14 AC 103 ms
76,932 KB
testcase_15 AC 69 ms
77,088 KB
testcase_16 AC 81 ms
77,300 KB
testcase_17 AC 141 ms
77,792 KB
testcase_18 AC 140 ms
77,592 KB
testcase_19 AC 49 ms
67,012 KB
testcase_20 AC 40 ms
60,512 KB
testcase_21 AC 85 ms
76,580 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