結果

問題 No.2106 Wild Cacco
ユーザー kwm_tkwm_t
提出日時 2022-10-22 15:54:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 2,015 bytes
コンパイル時間 4,371 ms
コンパイル使用メモリ 261,580 KB
実行使用メモリ 34,904 KB
最終ジャッジ日時 2023-09-14 09:44:10
合計ジャッジ時間 7,351 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
34,740 KB
testcase_01 AC 11 ms
34,612 KB
testcase_02 AC 11 ms
34,656 KB
testcase_03 AC 11 ms
34,828 KB
testcase_04 AC 11 ms
34,680 KB
testcase_05 AC 11 ms
34,692 KB
testcase_06 AC 11 ms
34,764 KB
testcase_07 AC 12 ms
34,680 KB
testcase_08 AC 11 ms
34,688 KB
testcase_09 AC 11 ms
34,896 KB
testcase_10 AC 11 ms
34,804 KB
testcase_11 AC 33 ms
34,904 KB
testcase_12 AC 46 ms
34,776 KB
testcase_13 AC 58 ms
34,848 KB
testcase_14 AC 40 ms
34,612 KB
testcase_15 AC 45 ms
34,756 KB
testcase_16 AC 60 ms
34,756 KB
testcase_17 AC 53 ms
34,704 KB
testcase_18 AC 46 ms
34,744 KB
testcase_19 AC 49 ms
34,696 KB
testcase_20 AC 52 ms
34,612 KB
testcase_21 AC 54 ms
34,708 KB
testcase_22 AC 42 ms
34,700 KB
testcase_23 AC 35 ms
34,700 KB
testcase_24 AC 44 ms
34,612 KB
testcase_25 AC 50 ms
34,752 KB
testcase_26 AC 78 ms
34,856 KB
testcase_27 AC 71 ms
34,756 KB
testcase_28 AC 73 ms
34,688 KB
testcase_29 AC 11 ms
34,600 KB
testcase_30 AC 11 ms
34,664 KB
testcase_31 AC 40 ms
34,692 KB
testcase_32 AC 36 ms
34,696 KB
testcase_33 AC 77 ms
34,836 KB
testcase_34 AC 77 ms
34,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
using mint = modint998244353;
const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
mint dp0[2001][2001];
mint dp1[2001][2001];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	string s; cin >> s;
	if (0 != s.size() % 2) {
		cout << 0 << endl;
		return 0;
	}
	int n = s.size() / 2;
	//vector dp0(n + 1, vector<mint>(n + 1));//[
	//vector dp1(n + 1, vector<mint>(n + 1));//]
	dp0[0][0] = 1;
	rep(i, s.size()) {
		if (('(' == s[i]) || ('.' == s[i])) {
			rep(j, n) {
				if ((i - j > n) || (i - j < 0) || ((j + 1) < (i - j)))continue;
				dp0[j + 1][i - j] += dp0[j][i - j];
				dp1[j + 1][i - j] += dp1[j][i - j];
			}
		}
		if ((')' == s[i]) || ('.' == s[i])) {
			rep(j, n) {
				if ((i - j > n) || (i - j < 0) || ((i - j) < (j + 1)))continue;
				dp0[i - j][j + 1] += dp0[i - j][j];
				dp1[i - j][j + 1] += dp1[i - j][j];
			}
		}
		if (('?' == s[i]) || ('.' == s[i])) {
			rep(j, n) {//[
				if ((i - j > n) || (i - j < 0) || ((j + 1) < (i - j)))continue;
				dp0[j + 1][i - j] += dp0[j][i - j];
			}
			rep(j, n) {//]
				if ((i - j > n) || (i - j < 0) || ((i - j) < (j + 1)))continue;
				dp1[i - j][j + 1] += dp0[i - j][j];
				dp1[i - j][j + 1] += dp1[i - j][j];
			}
		}
	}
	mint ans = dp0[n][n] + dp1[n][n];
	cout << ans.val() << endl;
	return 0;
}
0