結果

問題 No.3099 Parentheses Decomposition
ユーザー わん
提出日時 2025-05-19 00:38:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 618 ms / 2,000 ms
コード長 432 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 140,416 KB
最終ジャッジ日時 2025-05-19 00:38:29
合計ジャッジ時間 16,493 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353
fact = [1]
inv_fact = [1]
for i in range(5*10**5+10):
  fact.append(fact[i] * (i + 1) % MOD)
  inv_fact.append(pow(fact[i+1], MOD - 2, MOD))

def nCk(n, r):
  if r > n:
    return 0
  return (((fact[n] * inv_fact[n - r]) % MOD) * inv_fact[r]) % MOD

N = int(input())
S = input()

ans = 0
if S[0:2] != "()":
  for i in range(N//2+1):
    ans += pow(nCk(N//2, i), 2, MOD)
else:
  ans = pow(2, N//2, MOD)
print(ans%MOD)
0