結果
| 問題 |
No.3099 Parentheses Decomposition
|
| コンテスト | |
| ユーザー |
学ぶマン
|
| 提出日時 | 2025-04-12 17:13:54 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 136 ms / 2,000 ms |
| コード長 | 1,661 bytes |
| コンパイル時間 | 523 ms |
| コンパイル使用メモリ | 82,120 KB |
| 実行使用メモリ | 130,812 KB |
| 最終ジャッジ日時 | 2025-04-12 17:13:58 |
| 合計ジャッジ時間 | 3,124 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 20 |
ソースコード
import sys, math
sys.setrecursionlimit(10**8)
sys.set_int_max_str_digits(0)
INF = 10**18
MOD = 998244353
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import product, combinations, permutations, groupby, accumulate
from heapq import heapify, heappop, heappush
def I(): return sys.stdin.readline().rstrip()
def II(): return int(sys.stdin.readline().rstrip())
def IS(): return sys.stdin.readline().rstrip().split()
def MII(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(sys.stdin.readline().rstrip())
def TII(): return tuple(map(int, sys.stdin.readline().rstrip().split()))
def LII(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LSI(): return list(map(str, sys.stdin.readline().rstrip().split()))
def GMI(): return list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))
def kiriage(a, b): return (a+b-1)//b
#def check(i:int, j:int): return 0 <= i < H and 0 <= j < W
N = II()
S = I()
p = 998244353
if N == 2:
exit(print(2))
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
N2 = N//2
for i in range(2, N2 + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
# B型
if S[1] == ')':
ans = pow(2, N//2, p)
exit(print(ans))
# A型
ans = 0
for i in range(0, N2 + 1):
ans += cmb(N2, i, p)**2
ans %= p
print(ans)
学ぶマン