結果
問題 | No.2031 Colored Brackets |
ユーザー |
![]() |
提出日時 | 2022-08-06 00:02:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 163 ms / 2,000 ms |
コード長 | 605 bytes |
コンパイル時間 | 295 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 76,288 KB |
最終ジャッジ日時 | 2024-09-15 21:58:24 |
合計ジャッジ時間 | 3,694 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
import sysinput = sys.stdin.readlineN=int(input())S=input().strip()mod=998244353SUM=[0]for s in S:if s=="(":SUM.append(SUM[-1]+1)else:SUM.append(SUM[-1]-1)MAX=max(SUM)+1DP=[0]*MAXDP[0]=1for i in range(N):NDP=[0]*MAXx=SUM[i+1]for j in range(MAX):if S[i]=="(":if j+1<MAX:NDP[j+1]+=DP[j]NDP[j]+=DP[j]else:if j-1>=0:NDP[j-1]+=DP[j]if x-j>=0:NDP[j]+=DP[j]DP=[x%mod for x in NDP]print(DP[0])