結果
| 問題 |
No.2031 Colored Brackets
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-08-06 02:42:28 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 80 ms / 2,000 ms |
| コード長 | 683 bytes |
| コンパイル時間 | 1,981 ms |
| コンパイル使用メモリ | 192,820 KB |
| 最終ジャッジ日時 | 2025-01-30 18:57:35 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main () {
ll m = 998244353;
int N;
string s;
cin >> N >> s;
ll dp[3030][3030];
for (int i = 0; i <= N; i ++) {
for (int j = 0; j <= N; j ++) {
dp[i][j] = 0;
}
}
dp[0][0] = 1;
int now = 0;
for (int i = 1; i <= N; i ++) {
int x = (s[i - 1] == '(' ? 1 : -1);
now += x;
for (int j = 0; j <= now; j ++) {
dp[i][j] = dp[i - 1][j];
if (0 <= j - x && j - x <= N) {
dp[i][j] += dp[i - 1][j - x];
dp[i][j] %= m;
}
}
}
cout << dp[N][0] << endl;
}