結果
問題 | No.1810 RGB Biscuits |
ユーザー | lloyz |
提出日時 | 2022-01-14 22:19:35 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 309 ms / 2,000 ms |
コード長 | 1,039 bytes |
コンパイル時間 | 262 ms |
コンパイル使用メモリ | 82,424 KB |
実行使用メモリ | 78,304 KB |
最終ジャッジ日時 | 2024-04-30 15:32:40 |
合計ジャッジ時間 | 4,170 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
54,108 KB |
testcase_01 | AC | 53 ms
64,540 KB |
testcase_02 | AC | 45 ms
60,796 KB |
testcase_03 | AC | 70 ms
71,748 KB |
testcase_04 | AC | 71 ms
73,568 KB |
testcase_05 | AC | 284 ms
77,784 KB |
testcase_06 | AC | 289 ms
77,884 KB |
testcase_07 | AC | 309 ms
78,304 KB |
testcase_08 | AC | 289 ms
78,032 KB |
testcase_09 | AC | 293 ms
78,148 KB |
testcase_10 | AC | 230 ms
77,500 KB |
testcase_11 | AC | 89 ms
77,104 KB |
testcase_12 | AC | 84 ms
76,292 KB |
testcase_13 | AC | 79 ms
76,276 KB |
testcase_14 | AC | 129 ms
77,112 KB |
testcase_15 | AC | 89 ms
76,536 KB |
testcase_16 | AC | 111 ms
77,208 KB |
testcase_17 | AC | 193 ms
77,252 KB |
testcase_18 | AC | 203 ms
77,840 KB |
testcase_19 | AC | 63 ms
70,204 KB |
testcase_20 | AC | 46 ms
60,676 KB |
testcase_21 | AC | 122 ms
76,980 KB |
ソースコード
mod = 10**9 + 7 def matmul(A, B): Ah, Bh, Bw = len(A), len(B), len(B[0]) C = [[0 for _ in range(Bw)] for _ in range(Ah)] for i in range(Ah): for j in range(Bw): for k in range(Bh): C[i][j] += A[i][k] * B[k][j] C[i][j] %= mod return C # Mのk乗を効率的に計算する def doubling(M, k): k -= 1 Mc = M.copy() while k > 0: if k & 1 == 1: Mc = matmul(Mc, M) M = matmul(M, M) # Mの(2のi乗)の乗 を計算する k >>= 1 return Mc a, b = map(int, input().split()) A = [[1, 0, 0], [0, 1, 0], [a, b, 0]] B = [[0, 0, 1], [1, 0, 0], [0, 0, 0]] F = [[1], [1], [0]] M = matmul(B, A) n = int(input()) for _ in range(n): t = int(input()) q, r = divmod(t, 2) if q > 0: Mx = doubling(M, q) else: Mx = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] if r == 1: Mx = matmul(A, Mx) T = matmul(Mx, F) ans = 0 for i in range(3): ans += T[i][0] ans %= mod print(ans)