結果
問題 | No.1810 RGB Biscuits |
ユーザー | lloyz |
提出日時 | 2022-01-14 22:19:35 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 328 ms / 2,000 ms |
コード長 | 1,039 bytes |
コンパイル時間 | 404 ms |
コンパイル使用メモリ | 86,824 KB |
実行使用メモリ | 79,492 KB |
最終ジャッジ日時 | 2023-08-12 20:27:08 |
合計ジャッジ時間 | 5,295 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge7 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 76 ms
71,276 KB |
testcase_01 | AC | 89 ms
76,032 KB |
testcase_02 | AC | 80 ms
75,768 KB |
testcase_03 | AC | 100 ms
76,252 KB |
testcase_04 | AC | 100 ms
76,260 KB |
testcase_05 | AC | 310 ms
79,492 KB |
testcase_06 | AC | 308 ms
78,792 KB |
testcase_07 | AC | 328 ms
79,296 KB |
testcase_08 | AC | 308 ms
78,892 KB |
testcase_09 | AC | 311 ms
78,436 KB |
testcase_10 | AC | 253 ms
78,836 KB |
testcase_11 | AC | 119 ms
77,960 KB |
testcase_12 | AC | 114 ms
76,844 KB |
testcase_13 | AC | 110 ms
76,800 KB |
testcase_14 | AC | 160 ms
77,868 KB |
testcase_15 | AC | 118 ms
77,136 KB |
testcase_16 | AC | 143 ms
77,596 KB |
testcase_17 | AC | 223 ms
78,432 KB |
testcase_18 | AC | 234 ms
79,472 KB |
testcase_19 | AC | 98 ms
76,508 KB |
testcase_20 | AC | 82 ms
76,036 KB |
testcase_21 | AC | 151 ms
77,944 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)