結果

問題 No.2156 ぞい文字列
ユーザー kemunikukemuniku
提出日時 2022-12-09 21:53:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 854 bytes
コンパイル時間 388 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 53,120 KB
最終ジャッジ日時 2024-04-22 21:53:19
合計ジャッジ時間 2,176 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
52,992 KB
testcase_01 AC 43 ms
52,992 KB
testcase_02 AC 43 ms
52,948 KB
testcase_03 AC 43 ms
52,736 KB
testcase_04 AC 42 ms
52,608 KB
testcase_05 AC 42 ms
52,352 KB
testcase_06 AC 47 ms
52,480 KB
testcase_07 AC 41 ms
53,120 KB
testcase_08 AC 43 ms
51,968 KB
testcase_09 AC 46 ms
52,224 KB
testcase_10 AC 40 ms
52,480 KB
testcase_11 AC 46 ms
52,096 KB
testcase_12 AC 40 ms
52,352 KB
testcase_13 AC 47 ms
52,608 KB
testcase_14 AC 44 ms
52,352 KB
testcase_15 AC 47 ms
52,352 KB
testcase_16 AC 45 ms
52,224 KB
testcase_17 AC 43 ms
52,352 KB
testcase_18 AC 40 ms
52,096 KB
testcase_19 AC 50 ms
52,608 KB
権限があれば一括ダウンロードができます

ソースコード

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