結果

問題 No.2156 ぞい文字列
ユーザー iseeisee
提出日時 2022-12-09 21:38:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 782 bytes
コンパイル時間 557 ms
コンパイル使用メモリ 82,124 KB
実行使用メモリ 53,436 KB
最終ジャッジ日時 2024-04-22 21:16:54
合計ジャッジ時間 1,712 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,472 KB
testcase_01 AC 33 ms
52,820 KB
testcase_02 AC 33 ms
52,884 KB
testcase_03 AC 35 ms
53,148 KB
testcase_04 AC 35 ms
52,888 KB
testcase_05 AC 35 ms
53,332 KB
testcase_06 AC 35 ms
53,420 KB
testcase_07 AC 36 ms
52,740 KB
testcase_08 AC 34 ms
53,148 KB
testcase_09 AC 32 ms
53,432 KB
testcase_10 AC 32 ms
52,892 KB
testcase_11 AC 32 ms
52,756 KB
testcase_12 AC 33 ms
52,704 KB
testcase_13 AC 33 ms
52,832 KB
testcase_14 AC 30 ms
52,960 KB
testcase_15 AC 31 ms
53,280 KB
testcase_16 AC 32 ms
52,616 KB
testcase_17 AC 31 ms
52,896 KB
testcase_18 AC 32 ms
52,796 KB
testcase_19 AC 33 ms
53,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda: sys.stdin.readline().rstrip()

MOD = 998244353

def even(P):
    return P[0::2]

def odd(P):
    return P[1::2]

def mul(P, Q):
    N = len(P); M = len(Q)
    R = [0]*(N+M-1)
    for i in range(N):
        for j in range(M):
            R[i+j] += P[i]*Q[j]
            R[i+j] %= MOD
    return R

def negx(Q):
    return [(-n if i&1 else n) for i, n in enumerate(Q)]

def bostan_mori(N, P, Q):
    while N > 0:
        Qx = negx(Q)
        U = mul(P, Qx)
        if N&1: P = odd(U)
        else: P = even(U)
        Q = even(mul(Q, Qx))
        N >>= 1
    return P[0] * pow(Q[0], MOD-2, MOD)

def main():
    # 入力
    N = int(input())
    # 計算・出力
    print(bostan_mori(N+1, [0, 1], [1, -1, -1]) - 1)

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