結果

問題 No.2156 ぞい文字列
ユーザー tamlog06tamlog06
提出日時 2022-12-10 16:13:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 661 bytes
コンパイル時間 461 ms
コンパイル使用メモリ 82,544 KB
実行使用メモリ 54,448 KB
最終ジャッジ日時 2024-04-22 23:58:02
合計ジャッジ時間 2,011 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
53,880 KB
testcase_01 AC 34 ms
54,448 KB
testcase_02 AC 32 ms
53,044 KB
testcase_03 AC 33 ms
53,604 KB
testcase_04 AC 32 ms
52,944 KB
testcase_05 AC 33 ms
52,948 KB
testcase_06 AC 39 ms
54,008 KB
testcase_07 AC 36 ms
53,764 KB
testcase_08 AC 32 ms
53,268 KB
testcase_09 AC 32 ms
52,828 KB
testcase_10 AC 32 ms
54,040 KB
testcase_11 AC 33 ms
53,108 KB
testcase_12 AC 34 ms
52,392 KB
testcase_13 AC 34 ms
52,368 KB
testcase_14 AC 33 ms
54,376 KB
testcase_15 AC 33 ms
53,084 KB
testcase_16 AC 32 ms
52,516 KB
testcase_17 AC 32 ms
52,308 KB
testcase_18 AC 34 ms
53,020 KB
testcase_19 AC 35 ms
53,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353
N = int(input())

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

# Mのk乗を効率的に計算する
def powmat(M, k):
    k -= 1
    Mc = M.copy()
    while k > 0:
        if k & 1 == 1:
            Mc = dot(Mc, M)
        M = dot(M, M) # Mの(2のi乗)の乗 を計算する
        k >>= 1
    return Mc

M = [[1, 1], [1, 0]]
F = [[1], [0]]
Mn = powmat(M, N)
G = dot(Mn,F)
print((G[0][0]-1)%MOD)

0