結果
| 問題 | No.2031 Colored Brackets |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-08-16 13:00:01 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 631 bytes |
| 記録 | |
| コンパイル時間 | 1,351 ms |
| コンパイル使用メモリ | 186,156 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-04-19 06:20:05 |
| 合計ジャッジ時間 | 2,451 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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();
}