結果

問題 No.1810 RGB Biscuits
ユーザー lilictakalilictaka
提出日時 2022-05-09 17:01:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 288 ms / 2,000 ms
コード長 845 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 87,036 KB
実行使用メモリ 80,592 KB
最終ジャッジ日時 2023-09-23 15:16:39
合計ジャッジ時間 5,645 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,204 KB
testcase_01 AC 85 ms
76,544 KB
testcase_02 AC 70 ms
71,272 KB
testcase_03 AC 103 ms
77,820 KB
testcase_04 AC 101 ms
77,128 KB
testcase_05 AC 274 ms
78,876 KB
testcase_06 AC 282 ms
80,592 KB
testcase_07 AC 288 ms
79,720 KB
testcase_08 AC 288 ms
79,976 KB
testcase_09 AC 286 ms
80,112 KB
testcase_10 AC 236 ms
79,144 KB
testcase_11 AC 118 ms
77,800 KB
testcase_12 AC 106 ms
77,412 KB
testcase_13 AC 105 ms
77,924 KB
testcase_14 AC 161 ms
78,884 KB
testcase_15 AC 120 ms
79,508 KB
testcase_16 AC 141 ms
79,560 KB
testcase_17 AC 212 ms
80,348 KB
testcase_18 AC 222 ms
80,328 KB
testcase_19 AC 98 ms
77,212 KB
testcase_20 AC 69 ms
71,300 KB
testcase_21 AC 157 ms
80,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def mulmod(a,b,mod):
    return a*b%mod
def mat_mul_Pypy(A,B):
    return [[sum([mulmod(A[i][k],B[k][j],MOD) for k in range(len(B))])%MOD for j in range(len(B[0]))] for i in range(len(A))]

def mat_power_Pypy(A, N):#行列累乗
    P = [[1 if i==j else 0 for i in range(len(A[0]))] for j in range(len(A))]
    while N:
        if N & 1:
            P = mat_mul_Pypy(P, A)
        A = mat_mul_Pypy(A, A)
        N >>= 1
    return P
MOD = 10 ** 9 + 7
A,B = map(int,input().split())
N = int(input())
ANS = []
def solve(t):
    M = [[A,B],[1,0]]
    tmp = mat_power_Pypy(M,t//2)
    board = mat_mul_Pypy(tmp,[[1],[1]])
    if t % 2 == 0:
        return (board[0][0] + board[1][0]) % MOD
    else:
        return (board[0][0] * (A+1) + board[1][0] * (B+1)) % MOD
for _ in range(N):
    t = int(input())
    ANS.append(solve(t))
print(*ANS,sep='\n')
0