結果

問題 No.1810 RGB Biscuits
ユーザー customaddonecustomaddone
提出日時 2022-01-14 22:19:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 2,084 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 82,624 KB
実行使用メモリ 78,924 KB
最終ジャッジ日時 2024-04-30 15:32:35
合計ジャッジ時間 3,294 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
65,548 KB
testcase_01 AC 63 ms
67,812 KB
testcase_02 AC 58 ms
66,276 KB
testcase_03 AC 76 ms
73,684 KB
testcase_04 AC 75 ms
73,620 KB
testcase_05 AC 125 ms
78,084 KB
testcase_06 AC 154 ms
78,768 KB
testcase_07 AC 150 ms
78,924 KB
testcase_08 AC 151 ms
78,284 KB
testcase_09 AC 151 ms
78,544 KB
testcase_10 AC 139 ms
78,888 KB
testcase_11 AC 70 ms
70,904 KB
testcase_12 AC 87 ms
77,380 KB
testcase_13 AC 87 ms
77,512 KB
testcase_14 AC 114 ms
78,440 KB
testcase_15 AC 92 ms
77,388 KB
testcase_16 AC 96 ms
77,912 KB
testcase_17 AC 134 ms
78,548 KB
testcase_18 AC 134 ms
78,480 KB
testcase_19 AC 72 ms
72,444 KB
testcase_20 AC 58 ms
65,800 KB
testcase_21 AC 106 ms
77,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict, deque, Counter
from heapq import heapify, heappop, heappush
import math
from copy import deepcopy
from itertools import combinations, permutations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right

import sys

def input():
    return sys.stdin.readline().rstrip()
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getListGraph():
    return list(map(lambda x:int(x) - 1, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

mod = 10 ** 9 + 7
MOD = 998244353
# sys.setrecursionlimit(10000000)
inf = float('inf')
eps = 10 ** (-15)
dy = [0, 1, 0, -1]
dx = [1, 0, -1, 0]

#############
# Main Code #
#############

def array_cnt(ar1, ar2, m):
    h = len(ar1)
    w = len(ar2[0])
    row = ar1
    col = []
    for j in range(w):
        opt = []
        for i in range(len(ar2)):
            opt.append(ar2[i][j])
        col.append(opt)

    res = [[[0, 0] for i in range(w)] for i in range(h)]
    for i in range(h):
        for j in range(w):
            cnt = 0
            for x, y in zip(row[i], col[j]):
                cnt += x * y
            res[i][j] = cnt
            res[i][j] %= m
    return res

"""
R, G, B
操作1,操作2,操作1...
操作1 [[1, 0, A], [0, 1, B], [0, 0, 1]]
R, G, B + (R + G)
操作2 [[0, 1, 0], [0, 0, 0], [1, 0, 0]]
これをmixする
"""

A, B = getNM()
odd = [[1, 0, A], [0, 1, B], [0, 0, 1]]
even = [[0, 1, 0], [0, 0, 0], [1, 0, 0]]
mix = array_cnt(odd, even, mod)

T = getN()
k = 10 ** 20 # たくさん!
logk = k.bit_length()
dp = [[[0] * 3 for j in range(3)] for i in range(logk)]
dp[0] = mix
for i in range(1, logk):
    dp[i] = array_cnt(dp[i - 1], dp[i - 1], mod)

for _ in range(T):
    t = getN()
    mi_t = t // 2
    ans = [[1, 1, 0]]
    for i in range(mi_t.bit_length()):
        if mi_t & (1 << i):
            ans = array_cnt(ans, dp[i], mod)
    if t % 2 == 1:
        ans = array_cnt(ans, odd, mod)
    print(sum(ans[0]) % mod)
0