結果
問題 | No.2031 Colored Brackets |
ユーザー |
|
提出日時 | 2022-08-05 22:14:05 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 29 ms / 2,000 ms |
コード長 | 819 bytes |
コンパイル時間 | 1,365 ms |
コンパイル使用メモリ | 132,064 KB |
実行使用メモリ | 20,224 KB |
最終ジャッジ日時 | 2024-09-15 19:13:44 |
合計ジャッジ時間 | 2,640 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#define _USE_MATH_DEFINES #include<iostream> #include<vector> #include<algorithm> #include<cmath> #include<string> #include<iomanip> #include<numeric> #include<queue> #include<deque> #include<stack> #include<set> #include<map> #include<random> #include<bitset> #include<cassert> using namespace std; typedef long long ll; const int mod=998244353; const int dx[]={1,0,0,-1},dy[]={0,1,-1,0}; int dp[3001][1501]; int main(){ int n; string s; cin>>n>>s; dp[0][0]=1; int nest=0; for(int i=0;i<n;i++){ for(int na=0;na<=nest;na++){ if(s[i]=='('){ (dp[i+1][na+1]+=dp[i][na])%=mod; (dp[i+1][na]+=dp[i][na])%=mod; }else{ if(na!=0) (dp[i+1][na-1]+=dp[i][na])%=mod; if(na!=nest) (dp[i+1][na]+=dp[i][na])%=mod; } } if(s[i]=='(') nest++; else nest--; } cout<<dp[n][0]<<endl; }