結果
問題 | No.2031 Colored Brackets |
ユーザー |
|
提出日時 | 2022-08-05 22:06:54 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 212 ms / 2,000 ms |
コード長 | 993 bytes |
コンパイル時間 | 183 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 76,544 KB |
最終ジャッジ日時 | 2024-09-15 18:59:42 |
合計ジャッジ時間 | 4,830 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
from heapq import heapify, heappop, heappushimport sysint1 = lambda x: int(x) - 1# input = lambda: sys.stdin.buffer.readline()input = lambda: sys.stdin.readline().rstrip()ii = lambda: int(input())i1 = lambda: int1(input())mi = lambda: map(int, input().split())mi1 = lambda: map(int1, input().split())li = lambda: list(mi())li1 = lambda: list(mi1())lli = lambda n: [li() for _ in range(n)]INF = float("inf")# mod = int(1e9 + 7)mod = 998244353n = ii()a = [1 if c == "(" else -1 for c in input()]dp = [0] * (n + 1) # dp[x]= 赤の合計がxで青の合計がacc-xdp[0] = 1acc = 0for i in range(n):nxt = [0] * (n + 1)for x in range(n + 1):y = acc - xif 0 <= x + a[i] <= n:nxt[x + a[i]] += dp[x]if nxt[x + a[i]] >= mod:nxt[x + a[i]] -= modif 0 <= y + a[i] <= n:nxt[x] += dp[x]if nxt[x] >= mod:nxt[x] -= moddp = nxtacc += a[i]print(dp[0])