結果

問題 No.1810 RGB Biscuits
ユーザー 👑 H20H20
提出日時 2022-01-14 23:30:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 251 ms / 2,000 ms
コード長 670 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 82,440 KB
実行使用メモリ 78,588 KB
最終ジャッジ日時 2024-04-30 17:38:10
合計ジャッジ時間 3,706 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,328 KB
testcase_01 AC 52 ms
66,852 KB
testcase_02 AC 35 ms
53,700 KB
testcase_03 AC 79 ms
76,592 KB
testcase_04 AC 82 ms
76,884 KB
testcase_05 AC 200 ms
77,328 KB
testcase_06 AC 243 ms
77,580 KB
testcase_07 AC 251 ms
78,588 KB
testcase_08 AC 228 ms
77,584 KB
testcase_09 AC 223 ms
78,020 KB
testcase_10 AC 180 ms
77,356 KB
testcase_11 AC 61 ms
69,052 KB
testcase_12 AC 71 ms
76,116 KB
testcase_13 AC 71 ms
76,168 KB
testcase_14 AC 136 ms
77,616 KB
testcase_15 AC 81 ms
76,696 KB
testcase_16 AC 106 ms
77,240 KB
testcase_17 AC 180 ms
78,352 KB
testcase_18 AC 175 ms
78,268 KB
testcase_19 AC 60 ms
72,268 KB
testcase_20 AC 36 ms
53,376 KB
testcase_21 AC 115 ms
77,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

MOD = 10**9+7
def exp(mat_a, mat_b):
    new_mat = [[0]*len(mat_a) for _ in range(len(mat_a))]
    for i in range(len(mat_a)):
        for j in range(len(mat_a)):
            new_mat[i][j] = sum(mat_a[i][w]*mat_b[w][j] % MOD for w in range(len(mat_a))) % MOD
    return new_mat


for _ in range(N):
    T = int(input())
    MAP = [[A,B],[1,0]]
    ANS = [[1,0],[0,1]]
    K = T//2
    while K:
        if K & 1:
            ANS = exp(ANS, MAP)
        MAP = exp(MAP, MAP)
        K //= 2
    if T%2==1:
        print((sum(ANS[0])*(A+1)+sum(ANS[1])*(B+1))%MOD)
    else:
        print((sum(ANS[0])+sum(ANS[1]))%MOD)





0