結果
問題 | No.2031 Colored Brackets |
ユーザー |
![]() |
提出日時 | 2022-08-05 22:25:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 791 ms / 2,000 ms |
コード長 | 606 bytes |
コンパイル時間 | 452 ms |
コンパイル使用メモリ | 82,816 KB |
実行使用メモリ | 81,556 KB |
最終ジャッジ日時 | 2024-09-15 19:33:41 |
合計ジャッジ時間 | 7,148 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
import collectionsN = int(input())S = list(input())mod = 998244353DP = collections.defaultdict(int)DP[(0,0)]=1for s in S:NDP = collections.defaultdict(int)if s=='(':for k,v in DP.items():red,bule=kNDP[(red+1,bule)]=(NDP[(red+1,bule)]+v)%modNDP[(red,bule+1)]=(NDP[(red,bule+1)]+v)%modelse:for k,v in DP.items():red,bule=kif red>0:NDP[(red-1,bule)]=(NDP[(red-1,bule)]+v)%modif bule>0:NDP[(red,bule-1)]=(NDP[(red,bule-1)]+v)%modDP = NDPprint(DP[(0,0)])