結果

問題 No.2156 ぞい文字列
ユーザー kemunikukemuniku
提出日時 2022-12-09 21:53:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 854 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 82,276 KB
実行使用メモリ 52,608 KB
最終ジャッジ日時 2024-10-14 21:43:33
合計ジャッジ時間 1,914 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#N = int(input())
# 「ぞ」と「い」のみからなる文字列である。
# 「ぞ」から始まる。
# 「い」を少なくとも一文字含む。
# 「い」が 2 つ連続してはならない。
mod = 998244353
def mat_mul(a, b) :
    I, J, K = len(a), len(b[0]), len(b)
    c = [[0] * J for _ in range(I)]
    for i in range(I) :
        for j in range(J) :
            for k in range(K) :
                c[i][j] += a[i][k] * b[k][j]
            c[i][j] %= mod
    return c


def mat_pow(x, n):
    y = [[0] * len(x) for _ in range(len(x))]

    for i in range(len(x)):
        y[i][i] = 1

    while n > 0:
        if n & 1:
            y = mat_mul(x, y)
        x = mat_mul(x, x)
        n >>= 1

    return y
#https://qiita.com/ophhdn/items/e6451ec5983939ecbc5b

N = int(input())
m = [[1,1],[1,0]]
X = mat_pow(m, N+1)
print(X[1][0]-1)
0