結果

問題 No.2156 ぞい文字列
ユーザー roarisroaris
提出日時 2022-12-09 23:06:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 675 bytes
コンパイル時間 432 ms
コンパイル使用メモリ 82,328 KB
実行使用メモリ 54,752 KB
最終ジャッジ日時 2024-04-22 22:58:18
合計ジャッジ時間 1,929 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,436 KB
testcase_01 AC 39 ms
53,748 KB
testcase_02 AC 39 ms
52,592 KB
testcase_03 AC 43 ms
53,660 KB
testcase_04 AC 39 ms
53,092 KB
testcase_05 AC 40 ms
52,464 KB
testcase_06 AC 38 ms
52,884 KB
testcase_07 AC 40 ms
53,028 KB
testcase_08 AC 39 ms
52,584 KB
testcase_09 AC 40 ms
52,936 KB
testcase_10 AC 39 ms
53,928 KB
testcase_11 AC 38 ms
52,304 KB
testcase_12 AC 39 ms
54,192 KB
testcase_13 AC 38 ms
53,380 KB
testcase_14 AC 39 ms
52,780 KB
testcase_15 AC 39 ms
53,672 KB
testcase_16 AC 41 ms
52,820 KB
testcase_17 AC 38 ms
53,812 KB
testcase_18 AC 39 ms
53,032 KB
testcase_19 AC 39 ms
54,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def mat_mul(A, B):
    C = [[0]*len(B[0]) for _ in range(len(A))]
    
    for i in range(len(A)):
        for j in range(len(B[0])):
            for k in range(len(A[0])):
                C[i][j] += A[i][k]*B[k][j]
                C[i][j] %= MOD
    
    return C

def mat_pow(A, n):
    res = [[0]*len(A) for _ in range(len(A))]
    
    for i in range(len(A)):
        res[i][i] = 1
    
    while n>0:
        if n&1:
            res = mat_mul(res, A)
        
        n >>= 1
        A = mat_mul(A, A)
    
    return res

N = int(input())
M = [[1, 1], [1, 0]]
x = [[1], [0]]
MOD = 998244353
res = mat_mul(mat_pow(M, N-1), x)
ans = (res[0][0]+res[1][0]-1)%MOD
print(ans)
0