結果

問題 No.1310 量子アニーリング
ユーザー lam6er
提出日時 2025-03-20 20:54:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 624 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 82,164 KB
実行使用メモリ 67,488 KB
最終ジャッジ日時 2025-03-20 20:55:00
合計ジャッジ時間 2,229 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353

n = int(input())

# Precompute factorial and inverse factorial modulo MOD
fact = [1] * (n + 1)
for i in range(1, n + 1):
    fact[i] = fact[i-1] * i % MOD

inv_fact = [1] * (n + 1)
inv_fact[n] = pow(fact[n], MOD - 2, MOD)
for i in range(n-1, -1, -1):
    inv_fact[i] = inv_fact[i+1] * (i + 1) % MOD

ans = 0

for m in range(0, n + 1, 2):
    # Calculate combination C(n, m)
    c = fact[n] * inv_fact[m] % MOD
    c = c * inv_fact[n - m] % MOD
    
    k = abs(n - 2 * m)
    # Calculate 2^(k + 1) mod MOD
    term = pow(2, k, MOD)
    term = term * 2 % MOD
    
    ans = (ans + c * term) % MOD

print(ans)
0