結果

問題 No.2031 Colored Brackets
ユーザー 沙耶花
提出日時 2022-08-05 22:10:59
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 767 bytes
コンパイル時間 4,107 ms
コンパイル使用メモリ 252,796 KB
最終ジャッジ日時 2025-01-30 18:15:12
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000000



int main() {
    
	int n;
	cin>>n;
	
	string s;
	cin>>s;
	
	vector<mint> dp(n+1,0);
	dp[0] = 1;
	int sum = 0;
	rep(i,n){
		vector<mint> ndp(n+1,0);
		if(s[i]=='(')sum++;
		else sum--;
		rep(j,n+1){
			if(dp[j]==0)continue;
			{
				int jj = j;
				if(s[i]=='(')jj++;
				else jj--;
				int kk = sum - jj;
				if(kk>=0&&jj>=0){
					ndp[jj] += dp[j];					
				}
			}
			
			{
				int jj = j;
				int kk = sum - jj;
				if(kk>=0&&jj>=0){
					ndp[jj] += dp[j];					
				}
			}
			
		}
		swap(dp,ndp);
	}
		
	cout<<dp[0].val()<<endl;
	
    return 0;
}
0