結果
問題 | No.1810 RGB Biscuits |
ユーザー |
|
提出日時 | 2022-01-14 22:19:35 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 152 ms / 2,000 ms |
コード長 | 2,084 bytes |
コンパイル時間 | 464 ms |
コンパイル使用メモリ | 82,768 KB |
実行使用メモリ | 78,880 KB |
最終ジャッジ日時 | 2024-11-20 11:36:25 |
合計ジャッジ時間 | 3,617 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
from collections import defaultdict, deque, Counterfrom heapq import heapify, heappop, heappushimport mathfrom copy import deepcopyfrom itertools import combinations, permutations, product, combinations_with_replacementfrom bisect import bisect_left, bisect_rightimport sysdef 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 + 7MOD = 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 = ar1col = []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 = 0for x, y in zip(row[i], col[j]):cnt += x * yres[i][j] = cntres[i][j] %= mreturn 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] = mixfor 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 // 2ans = [[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)