結果

問題 No.1810 RGB Biscuits
ユーザー 👑 rin204rin204
提出日時 2022-01-21 01:10:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 276 ms / 2,000 ms
コード長 762 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 82,276 KB
実行使用メモリ 84,832 KB
最終ジャッジ日時 2024-05-03 12:36:01
合計ジャッジ時間 4,426 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
53,632 KB
testcase_01 AC 75 ms
71,296 KB
testcase_02 AC 43 ms
53,888 KB
testcase_03 AC 91 ms
76,928 KB
testcase_04 AC 93 ms
77,184 KB
testcase_05 AC 246 ms
83,892 KB
testcase_06 AC 274 ms
84,832 KB
testcase_07 AC 276 ms
84,264 KB
testcase_08 AC 276 ms
83,852 KB
testcase_09 AC 266 ms
84,532 KB
testcase_10 AC 248 ms
83,300 KB
testcase_11 AC 68 ms
67,968 KB
testcase_12 AC 105 ms
77,856 KB
testcase_13 AC 142 ms
78,504 KB
testcase_14 AC 130 ms
79,528 KB
testcase_15 AC 101 ms
78,004 KB
testcase_16 AC 102 ms
77,860 KB
testcase_17 AC 201 ms
81,620 KB
testcase_18 AC 205 ms
81,592 KB
testcase_19 AC 76 ms
75,648 KB
testcase_20 AC 44 ms
53,888 KB
testcase_21 AC 132 ms
78,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from copy import deepcopy

MOD = 10 ** 9 + 7

a, b = map(int, input().split())
n = int(input())
for _ in range(n):
    t = int(input())
    A = [[a, b], [1, 0]]
    B = [1, 1]
    x = t // 2
    while x:
        if x & 1:
            C = [0, 0]
            for i in range(2):
                for j in range(2):
                    C[i] += A[i][j] * B[j]
                C[i] %= MOD
            B = C.copy()
        x >>= 1
        C = [[0, 0], [0, 0]]
        for i in range(2):
            for j in range(2):
                for k in range(2):
                    C[i][j] += A[i][k] * A[k][j]
                C[i][j] %= MOD
        A = deepcopy(C)
    
    if t % 2 == 0:
        print(sum(B) % MOD)
    else:
        print((sum(B) + B[0] * a + B[1] * b) % MOD)
0