結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,116 KB
testcase_01 AC 34 ms
53,488 KB
testcase_02 AC 33 ms
53,408 KB
testcase_03 AC 33 ms
53,112 KB
testcase_04 AC 34 ms
53,732 KB
testcase_05 AC 34 ms
53,080 KB
testcase_06 AC 34 ms
53,208 KB
testcase_07 AC 34 ms
54,100 KB
testcase_08 AC 34 ms
53,424 KB
testcase_09 AC 32 ms
53,368 KB
testcase_10 AC 35 ms
52,476 KB
testcase_11 AC 33 ms
53,116 KB
testcase_12 AC 33 ms
52,560 KB
testcase_13 AC 33 ms
52,468 KB
testcase_14 AC 31 ms
53,292 KB
testcase_15 AC 34 ms
52,940 KB
testcase_16 AC 33 ms
52,532 KB
testcase_17 AC 32 ms
53,004 KB
testcase_18 AC 33 ms
53,212 KB
testcase_19 AC 33 ms
53,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N =int(input())
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]%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 //=2
    return y


matrix = [[1,1],[1,0]]
mat2 = [[1],[1]]

tmp = mat_pow(matrix,N-2)
ans = mat_mul(tmp,mat2)
print((sum(ans[0]+ans[1])-1)%mod)
0