結果

問題 No.1810 RGB Biscuits
ユーザー tktk_snsntktk_snsn
提出日時 2022-01-14 22:47:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 190 ms / 2,000 ms
コード長 1,103 bytes
コンパイル時間 628 ms
コンパイル使用メモリ 82,360 KB
実行使用メモリ 77,840 KB
最終ジャッジ日時 2024-04-30 16:27:20
合計ジャッジ時間 3,175 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,552 KB
testcase_01 AC 44 ms
63,740 KB
testcase_02 AC 41 ms
60,816 KB
testcase_03 AC 51 ms
68,428 KB
testcase_04 AC 55 ms
68,500 KB
testcase_05 AC 173 ms
77,064 KB
testcase_06 AC 186 ms
77,784 KB
testcase_07 AC 190 ms
77,684 KB
testcase_08 AC 186 ms
77,840 KB
testcase_09 AC 185 ms
77,168 KB
testcase_10 AC 151 ms
77,632 KB
testcase_11 AC 80 ms
76,032 KB
testcase_12 AC 71 ms
76,336 KB
testcase_13 AC 70 ms
76,584 KB
testcase_14 AC 107 ms
77,412 KB
testcase_15 AC 78 ms
76,276 KB
testcase_16 AC 88 ms
77,492 KB
testcase_17 AC 124 ms
76,692 KB
testcase_18 AC 147 ms
77,580 KB
testcase_19 AC 52 ms
66,340 KB
testcase_20 AC 43 ms
61,604 KB
testcase_21 AC 98 ms
77,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
mod = 10 ** 9 + 7


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


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


def test(A, B, T):
    X = [
        [1, 0, 0],
        [0, 1, 0],
        [A, B, 1],
    ]

    Y = [
        [0, 0, 1],
        [1, 0, 0],
        [0, 0, 0],
    ]

    XY = mat_mul(Y, X)

    d, m = divmod(T, 2)
    P = mat_pow(XY, d)
    if m:
        P = mat_mul(X, P)
    res = P[0][0] + P[0][1] + P[1][0] + P[1][1] + P[2][0] + P[2][1]
    return res % mod


A, B = map(int, input().split())
N = int(input())
for _ in range(N):
    T = int(input())
    print(test(A, B, T))
0