結果
問題 |
No.2031 Colored Brackets
|
ユーザー |
|
提出日時 | 2022-08-16 13:00:01 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 631 bytes |
コンパイル時間 | 1,370 ms |
コンパイル使用メモリ | 174,276 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-03 04:28:48 |
合計ジャッジ時間 | 2,410 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/modint> using namespace std; using namespace atcoder; using mint = modint998244353; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; string s; cin >> s; vector<mint> dp(n + 1); dp[0] = 1; int sum = 0; for (char c : s) { sum += (c == '(' ? 1 : -1); vector<mint> cur(n + 1); for (int j = 0; j <= sum; j++) { cur[j] = dp[j]; if (j > 0 || c == ')') { cur[j] += dp[j - (c == '(' ? 1 : -1)]; } } dp = cur; } cout << dp[0].val(); }