結果
問題 | No.2031 Colored Brackets |
ユーザー |
![]() |
提出日時 | 2022-08-05 22:05:33 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 78 ms / 2,000 ms |
コード長 | 1,179 bytes |
コンパイル時間 | 1,824 ms |
コンパイル使用メモリ | 171,596 KB |
実行使用メモリ | 73,856 KB |
最終ジャッジ日時 | 2024-09-15 18:55:21 |
合計ジャッジ時間 | 4,132 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll,ll> P; typedef vector<ll> VI; typedef vector<VI> VVI; #define REP(i,n) for(ll i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;}; template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;}; constexpr ll MOD=998244353; constexpr ll INF=2e18; int main(){ int n; cin >> n; string s; cin >> s; VVI dp(n+1,VI(n+1,0)); dp[0][0]=1; int x=0; REP(i,n){ if(s[i]=='('){ x++; REP(j,n){ if(j==0) dp[i+1][j]+=dp[i][j]; else dp[i+1][j]+=dp[i][j-1]+dp[i][j]; dp[i+1][j]%=MOD; } } else{ x--; REP(j,n){ dp[i+1][j]+=dp[i][j+1]; dp[i+1][j]%=MOD; } REP(j,x+1){ dp[i+1][j]+=dp[i][j]; dp[i+1][j]%=MOD; } } } ll ans=0; REP(i,n+1) ans=(ans+dp[n][i])%MOD; cout << ans << endl; return 0; }