結果

問題 No.2156 ぞい文字列
ユーザー roarisroaris
提出日時 2022-12-09 23:06:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 675 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 87,224 KB
実行使用メモリ 71,620 KB
最終ジャッジ日時 2023-08-05 00:58:24
合計ジャッジ時間 2,471 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,124 KB
testcase_01 AC 66 ms
71,392 KB
testcase_02 AC 66 ms
71,368 KB
testcase_03 AC 67 ms
71,332 KB
testcase_04 AC 67 ms
71,360 KB
testcase_05 AC 68 ms
71,256 KB
testcase_06 AC 68 ms
71,256 KB
testcase_07 AC 68 ms
71,260 KB
testcase_08 AC 67 ms
71,456 KB
testcase_09 AC 67 ms
71,620 KB
testcase_10 AC 67 ms
71,360 KB
testcase_11 AC 67 ms
71,132 KB
testcase_12 AC 67 ms
71,384 KB
testcase_13 AC 68 ms
71,328 KB
testcase_14 AC 68 ms
71,428 KB
testcase_15 AC 66 ms
71,508 KB
testcase_16 AC 66 ms
71,560 KB
testcase_17 AC 67 ms
71,556 KB
testcase_18 AC 67 ms
71,560 KB
testcase_19 AC 68 ms
71,560 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