結果

問題 No.2156 ぞい文字列
ユーザー ThetaTheta
提出日時 2022-12-12 16:58:18
言語 Python3
(3.11.2 + numpy 1.24.2 + scipy 1.10.1)
結果
RE  
実行時間 -
コード長 778 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 11,016 KB
実行使用メモリ 32,404 KB
最終ジャッジ日時 2023-08-06 11:32:06
合計ジャッジ時間 5,930 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 143 ms
30,324 KB
testcase_17 AC 144 ms
30,524 KB
testcase_18 WA -
testcase_19 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from typing import Sequence
import numpy as np


def mat_mul(mat1: np.matrix, mat2: np.matrix, mod: int = None):
    ans = mat1 * mat2
    return ans if mod is None else ans % mod


def mat_pow(mat1: Sequence[Sequence[int]], n: int, mod: int = None) -> Sequence[Sequence[int]]:
    mat1 = np.matrix(mat1)
    ans = np.identity(len(mat1))
    while n > 0:
        if n & 1:
            ans = mat_mul(ans, mat1)
        mat1 = mat_mul(mat1, mat1)
        n >>= 1
    return ans


def main():
    N = int(input())
    MOD = 998244353
    fib_matrix = np.matrix([[1, 1], [1, 0]])
    init = np.array(([1, 0], )).T
    fib_matrix_pow = mat_pow(fib_matrix, N, MOD)
    fib_N = np.dot(fib_matrix_pow, init)
    print(int(fib_N[0, 0] - 1) % MOD)


if __name__ == "__main__":
    main()
0