結果
問題 |
No.2031 Colored Brackets
|
ユーザー |
![]() |
提出日時 | 2022-08-06 23:39:59 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 80 ms / 2,000 ms |
コード長 | 783 bytes |
コンパイル時間 | 2,037 ms |
コンパイル使用メモリ | 195,304 KB |
最終ジャッジ日時 | 2025-01-30 19:10:32 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include <bits/stdc++.h> using namespace std; ll dp[3030][3030]; const int MOD=998244353; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; string s; cin>>n>>s; dp[0][0]=1; vector<int> S(n+1); rep(i,n){ if(s[i]=='(') S[i+1]=S[i]+1; else S[i+1]=S[i]-1; } rep(i,n){ rep(j,n+1){ if(s[i]=='('){ if(j+1<=S[i+1]) dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j])%MOD; if(S[i+1]-j>=0) dp[i+1][j]=(dp[i+1][j]+dp[i][j])%MOD; } else{ if(j-1>=0) dp[i+1][j-1]=(dp[i+1][j-1]+dp[i][j])%MOD; if(S[i+1]-j>=0) dp[i+1][j]=(dp[i+1][j]+dp[i][j])%MOD; } } } cout<<dp[n][0]<<endl; return 0; }