結果

問題 No.1810 RGB Biscuits
ユーザー customaddonecustomaddone
提出日時 2022-01-14 22:19:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 200 ms / 2,000 ms
コード長 2,084 bytes
コンパイル時間 1,054 ms
コンパイル使用メモリ 86,884 KB
実行使用メモリ 81,084 KB
最終ジャッジ日時 2023-08-12 20:27:02
合計ジャッジ時間 4,978 ms
ジャッジサーバーID
(参考情報)
judge2 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
77,936 KB
testcase_01 AC 113 ms
77,804 KB
testcase_02 AC 109 ms
77,648 KB
testcase_03 AC 122 ms
78,108 KB
testcase_04 AC 124 ms
77,960 KB
testcase_05 AC 173 ms
79,952 KB
testcase_06 AC 200 ms
80,056 KB
testcase_07 AC 197 ms
80,244 KB
testcase_08 AC 194 ms
80,312 KB
testcase_09 AC 195 ms
79,928 KB
testcase_10 AC 177 ms
79,668 KB
testcase_11 AC 121 ms
78,416 KB
testcase_12 AC 129 ms
78,668 KB
testcase_13 AC 132 ms
78,808 KB
testcase_14 AC 156 ms
79,500 KB
testcase_15 AC 139 ms
78,820 KB
testcase_16 AC 138 ms
79,208 KB
testcase_17 AC 176 ms
80,200 KB
testcase_18 AC 177 ms
81,084 KB
testcase_19 AC 128 ms
78,028 KB
testcase_20 AC 117 ms
78,020 KB
testcase_21 AC 153 ms
79,256 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