結果

問題 No.1810 RGB Biscuits
ユーザー SidewaysOwlSidewaysOwl
提出日時 2022-01-14 22:58:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 949 bytes
コンパイル時間 456 ms
コンパイル使用メモリ 82,436 KB
実行使用メモリ 77,188 KB
最終ジャッジ日時 2024-04-30 16:45:43
合計ジャッジ時間 2,494 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
59,648 KB
testcase_01 AC 47 ms
61,972 KB
testcase_02 AC 42 ms
59,108 KB
testcase_03 AC 49 ms
64,852 KB
testcase_04 AC 50 ms
65,836 KB
testcase_05 AC 95 ms
76,536 KB
testcase_06 AC 120 ms
77,028 KB
testcase_07 AC 119 ms
77,120 KB
testcase_08 AC 120 ms
77,140 KB
testcase_09 AC 125 ms
77,188 KB
testcase_10 AC 109 ms
77,180 KB
testcase_11 AC 63 ms
72,888 KB
testcase_12 AC 52 ms
68,672 KB
testcase_13 AC 49 ms
67,076 KB
testcase_14 AC 81 ms
76,628 KB
testcase_15 AC 54 ms
67,384 KB
testcase_16 AC 61 ms
74,500 KB
testcase_17 AC 105 ms
76,992 KB
testcase_18 AC 111 ms
76,980 KB
testcase_19 AC 45 ms
64,008 KB
testcase_20 AC 38 ms
60,992 KB
testcase_21 AC 68 ms
76,368 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