結果
| 問題 |
No.2156 ぞい文字列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-12-09 23:35:58 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 41 ms / 2,000 ms |
| コード長 | 681 bytes |
| コンパイル時間 | 195 ms |
| コンパイル使用メモリ | 81,872 KB |
| 実行使用メモリ | 53,120 KB |
| 最終ジャッジ日時 | 2024-10-14 23:07:35 |
| 合計ジャッジ時間 | 1,675 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
n = int(input())
mod = 998244353
def matmul(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 doubling(M, k):
k -= 1
Mc = M.copy()
while k > 0:
if k & 1 == 1:
Mc = matmul(Mc, M)
M = matmul(M, M) # Mの(2のi乗)の乗 を計算する
k >>= 1
return Mc
M = [[1, 1], [1, 0]]
F = [[1], [0]]
Mn = doubling(M, n)
G = matmul(Mn, F)
print((G[0][0] - 1) % mod)