結果

問題 No.2600 Avator Height
ユーザー ThetaTheta
提出日時 2024-02-02 19:38:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,942 ms / 2,000 ms
コード長 828 bytes
コンパイル時間 205 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 205,568 KB
最終ジャッジ日時 2024-02-02 19:39:32
合計ジャッジ時間 49,824 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 515 ms
205,548 KB
testcase_01 AC 1,933 ms
197,312 KB
testcase_02 AC 1,854 ms
167,676 KB
testcase_03 AC 1,874 ms
159,980 KB
testcase_04 AC 1,891 ms
150,216 KB
testcase_05 AC 1,891 ms
125,980 KB
testcase_06 AC 1,868 ms
138,196 KB
testcase_07 AC 1,845 ms
148,728 KB
testcase_08 AC 1,837 ms
166,496 KB
testcase_09 AC 1,879 ms
173,964 KB
testcase_10 AC 1,899 ms
170,076 KB
testcase_11 AC 1,927 ms
132,540 KB
testcase_12 AC 1,942 ms
194,660 KB
testcase_13 AC 1,899 ms
161,144 KB
testcase_14 AC 1,894 ms
148,076 KB
testcase_15 AC 1,891 ms
142,960 KB
testcase_16 AC 1,891 ms
160,776 KB
testcase_17 AC 1,860 ms
127,544 KB
testcase_18 AC 1,830 ms
116,788 KB
testcase_19 AC 1,832 ms
139,260 KB
testcase_20 AC 1,822 ms
129,796 KB
testcase_21 AC 1,861 ms
181,668 KB
testcase_22 AC 1,853 ms
142,588 KB
testcase_23 AC 1,876 ms
188,088 KB
testcase_24 AC 1,008 ms
9,984 KB
testcase_25 AC 1,577 ms
205,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import cache
import sys

sys.setrecursionlimit(10000000)


@cache
def fibonacci(N: int) -> int:
    if N in (1, 2):
        return 1
    return fibonacci(N - 2) + fibonacci(N - 1)


@cache
def fibonacci_mod(N: int, mod: int) -> int:
    if N in (1, 2):
        return 1
    return (fibonacci_mod(N - 2, mod) + fibonacci_mod(N - 1, mod)) % mod


@cache
def nacci_e(N: int, mod: int) -> int:
    if N == 1:
        return 1
    if N == 2:
        return 3
    return (nacci_e(N - 1, mod) + nacci_e(N - 2, mod)) % mod


def calc_width_diff(N: int) -> int:
    MOD = 998244353
    return ((5 * fibonacci_mod(N, MOD) ** 2) %
            MOD - nacci_e(N, MOD) ** 2) % MOD


def main():
    for _ in range(int(input())):
        N = int(input())
        print(calc_width_diff(N))


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