結果
| 問題 | No.2156 ぞい文字列 |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2026-11-01 10:54:06 |
| 言語 | PyPy3 (8.0.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 34 ms / 2,000 ms |
| + 786µs | |
| コード長 | 748 bytes |
| 記録 | |
| コンパイル時間 | 631 ms |
| コンパイル使用メモリ | 64,500 KB |
| 実行使用メモリ | 53,612 KB |
| 最終ジャッジ日時 | 2026-11-01 10:54:10 |
| 合計ジャッジ時間 | 3,576 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 17 |
ソースコード
def mat_mul(a, b, mod):
ar, ac, br, bc = len(a), len(a[0]), len(b), len(b[0])
assert ac == br
res = [[0] * bc for _ in range(ar)]
for i in range(ar):
out = res[i]
for j in range(bc):
r = a[i]
x = 0
for k in range(ac):
x += r[k] * b[k][j]
x %= mod
out[j] = x
return res
def mat_power(m, n: int):
assert n > 0
if n == 1: return m
res = mat_power(m, n // 2)
res = mat_mul(res, res, MOD)
if n % 2 == 1:
res = mat_mul(res, m, MOD)
return res
MOD = 998244353
N = int(input())
m = [[1, 1], [1, 0]]
res = mat_mul(mat_power(m, N-1), [[1], [0]], MOD)
ans = (res[0][0] + res[1][0] - 1) % MOD
print(ans)
norioc