結果
問題 | No.1810 RGB Biscuits |
ユーザー | H3PO4 |
提出日時 | 2022-01-14 21:46:11 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,105 ms / 2,000 ms |
コード長 | 835 bytes |
コンパイル時間 | 240 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 44,536 KB |
最終ジャッジ日時 | 2024-04-30 13:58:14 |
合計ジャッジ時間 | 17,336 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 430 ms
44,272 KB |
testcase_01 | AC | 445 ms
44,268 KB |
testcase_02 | AC | 440 ms
44,536 KB |
testcase_03 | AC | 452 ms
44,012 KB |
testcase_04 | AC | 449 ms
44,140 KB |
testcase_05 | AC | 1,057 ms
44,392 KB |
testcase_06 | AC | 1,086 ms
44,140 KB |
testcase_07 | AC | 1,088 ms
43,892 KB |
testcase_08 | AC | 1,092 ms
44,008 KB |
testcase_09 | AC | 1,105 ms
44,020 KB |
testcase_10 | AC | 837 ms
44,300 KB |
testcase_11 | AC | 461 ms
44,012 KB |
testcase_12 | AC | 449 ms
43,876 KB |
testcase_13 | AC | 455 ms
43,884 KB |
testcase_14 | AC | 541 ms
44,056 KB |
testcase_15 | AC | 472 ms
43,888 KB |
testcase_16 | AC | 470 ms
44,148 KB |
testcase_17 | AC | 744 ms
44,020 KB |
testcase_18 | AC | 758 ms
43,892 KB |
testcase_19 | AC | 441 ms
44,268 KB |
testcase_20 | AC | 442 ms
44,396 KB |
testcase_21 | AC | 510 ms
44,272 KB |
ソースコード
import numpy as np MOD = 10 ** 9 + 7 def pow_matrix_mod(x, n, mod=MOD): if not n: return np.eye(len(x), dtype=object) if n % 2 == 0: return pow_matrix_mod(x @ x % mod, n // 2) % mod else: return x @ pow_matrix_mod(x @ x % mod, (n - 1) // 2) % mod A, B = map(int, input().split()) matr_odd = np.array([[1, 0, A], [0, 1, B], [0, 0, 1]], dtype=object) matr_even = np.array([[0, 1, 0], [0, 0, 0], [1, 0, 0]], dtype=object) matr = (matr_odd @ matr_even) % MOD N = int(input()) for _ in range(N): T = int(input()) p = pow_matrix_mod(matr, T // 2) if T % 2: p = p @ matr_odd p %= MOD ans = np.sum(np.array([1, 1, 0]) @ p) % MOD print(ans)