結果

問題 No.1706 Many Bus Stops (hard)
ユーザー H3PO4H3PO4
提出日時 2021-10-08 23:52:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 572 bytes
コンパイル時間 564 ms
コンパイル使用メモリ 10,852 KB
実行使用メモリ 29,712 KB
最終ジャッジ日時 2023-09-30 14:19:27
合計ジャッジ時間 9,871 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
29,572 KB
testcase_01 AC 130 ms
29,528 KB
testcase_02 AC 131 ms
29,552 KB
testcase_03 AC 130 ms
29,540 KB
testcase_04 AC 134 ms
29,548 KB
testcase_05 AC 133 ms
29,580 KB
testcase_06 AC 132 ms
29,568 KB
testcase_07 AC 131 ms
29,512 KB
testcase_08 AC 131 ms
29,492 KB
testcase_09 AC 130 ms
29,560 KB
testcase_10 AC 131 ms
29,684 KB
testcase_11 AC 132 ms
29,628 KB
testcase_12 AC 132 ms
29,504 KB
testcase_13 AC 132 ms
29,580 KB
testcase_14 AC 132 ms
29,708 KB
testcase_15 AC 131 ms
29,556 KB
testcase_16 AC 132 ms
29,460 KB
testcase_17 AC 133 ms
29,580 KB
testcase_18 AC 133 ms
29,532 KB
testcase_19 AC 133 ms
29,588 KB
testcase_20 AC 132 ms
29,452 KB
testcase_21 AC 133 ms
29,572 KB
testcase_22 AC 132 ms
29,564 KB
testcase_23 AC 133 ms
29,520 KB
testcase_24 AC 137 ms
29,712 KB
testcase_25 AC 136 ms
29,584 KB
testcase_26 AC 133 ms
29,524 KB
testcase_27 AC 132 ms
29,540 KB
testcase_28 AC 132 ms
29,544 KB
testcase_29 AC 131 ms
29,580 KB
testcase_30 AC 131 ms
29,536 KB
testcase_31 AC 131 ms
29,568 KB
testcase_32 AC 131 ms
29,712 KB
testcase_33 AC 133 ms
29,464 KB
testcase_34 AC 130 ms
29,508 KB
testcase_35 AC 130 ms
29,496 KB
testcase_36 AC 132 ms
29,576 KB
testcase_37 AC 134 ms
29,456 KB
testcase_38 AC 130 ms
29,480 KB
testcase_39 AC 130 ms
29,572 KB
testcase_40 AC 130 ms
29,580 KB
testcase_41 AC 129 ms
29,608 KB
testcase_42 AC 132 ms
29,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

C, N, M = map(int, input().split())
MOD = 10 ** 9 + 7
iC = pow(C, -1, MOD)


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 = np.array([[iC, 0, 0, 1 - iC],
              [0, iC, iC, 1 - 2 * iC],
              [1, 0, 0, 0],
              [0, 1, 0, 0]], dtype=object)
tmp = pow_matrix_mod(A, N)[0][0]
ans = (1 - pow(1 - tmp, M, MOD)) % MOD
print(ans)
0