結果

問題 No.2156 ぞい文字列
ユーザー ThetaTheta
提出日時 2022-12-12 16:58:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 778 bytes
コンパイル時間 81 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 44,576 KB
最終ジャッジ日時 2024-04-24 07:24:05
合計ジャッジ時間 11,501 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 452 ms
44,452 KB
testcase_17 AC 457 ms
44,076 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