結果

問題 No.1810 RGB Biscuits
ユーザー SidewaysOwlSidewaysOwl
提出日時 2022-01-14 22:58:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 949 bytes
コンパイル時間 339 ms
コンパイル使用メモリ 86,840 KB
実行使用メモリ 79,716 KB
最終ジャッジ日時 2023-08-12 21:40:59
合計ジャッジ時間 3,970 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
75,776 KB
testcase_01 AC 80 ms
76,228 KB
testcase_02 AC 78 ms
75,772 KB
testcase_03 AC 89 ms
76,448 KB
testcase_04 AC 88 ms
76,580 KB
testcase_05 AC 159 ms
77,628 KB
testcase_06 AC 165 ms
78,032 KB
testcase_07 AC 165 ms
78,564 KB
testcase_08 AC 167 ms
77,952 KB
testcase_09 AC 165 ms
78,748 KB
testcase_10 AC 156 ms
78,116 KB
testcase_11 AC 103 ms
76,572 KB
testcase_12 AC 91 ms
76,728 KB
testcase_13 AC 89 ms
76,560 KB
testcase_14 AC 120 ms
77,676 KB
testcase_15 AC 89 ms
76,532 KB
testcase_16 AC 104 ms
77,248 KB
testcase_17 AC 148 ms
78,960 KB
testcase_18 AC 159 ms
79,716 KB
testcase_19 AC 84 ms
76,364 KB
testcase_20 AC 77 ms
75,420 KB
testcase_21 AC 105 ms
77,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

a,b = map(int,input().split())
n = int(input())
l = [[[1,0,0],[0,1,0],[a,b,0]]]
ki = l[0][::]
gu = [[0,0,1],[1,0,0],[0,0,0]]
mod = 10 ** 9 + 7
def multiply(l1,l2):
    res = [[0] * 3 for _ in range(3)]
    for i in range(3):
        for j in range(3):
            e_res = 0
            for k in range(3):
                e_res += l1[i][k] * l2[k][j]
                e_res %= mod
            res[i][j] = e_res
    return res
rui = multiply(gu,ki)
l.append(rui)
for i in range(2,(10**18).bit_length()):
    l.append(multiply(l[i-1][::],l[i-1][::]))
    
for _ in range(n):
    T = int(input())
    t = T
    cnt = 0
    res_rui = [[1,0,0],[0,1,0],[0,0,1]]
    while t:
        if t & 1:
            if cnt != 0:
                res_rui = multiply(l[cnt],res_rui)
        t >>= 1
        cnt += 1
    if T & 1:
        res_rui = multiply(l[0],res_rui)
#     print(res_rui)
    print((sum(res_rui[0][:2])+ sum(res_rui[1][:2]) + sum(res_rui[2][:2]))%mod)
0