結果

問題 No.2106 Wild Cacco
ユーザー 沙耶花沙耶花
提出日時 2022-10-21 23:28:22
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 957 ms / 2,000 ms
コード長 1,684 bytes
コンパイル時間 4,741 ms
コンパイル使用メモリ 268,628 KB
実行使用メモリ 8,108 KB
最終ジャッジ日時 2023-09-13 23:35:04
合計ジャッジ時間 25,336 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
7,488 KB
testcase_01 AC 11 ms
7,456 KB
testcase_02 AC 11 ms
7,508 KB
testcase_03 AC 11 ms
7,628 KB
testcase_04 AC 12 ms
7,440 KB
testcase_05 AC 12 ms
7,528 KB
testcase_06 AC 12 ms
7,512 KB
testcase_07 AC 12 ms
7,516 KB
testcase_08 AC 13 ms
7,500 KB
testcase_09 AC 12 ms
7,716 KB
testcase_10 AC 12 ms
7,684 KB
testcase_11 AC 679 ms
7,840 KB
testcase_12 AC 747 ms
7,900 KB
testcase_13 AC 806 ms
7,908 KB
testcase_14 AC 805 ms
7,856 KB
testcase_15 AC 836 ms
8,108 KB
testcase_16 AC 914 ms
7,960 KB
testcase_17 AC 908 ms
7,884 KB
testcase_18 AC 889 ms
7,952 KB
testcase_19 AC 899 ms
7,936 KB
testcase_20 AC 893 ms
7,932 KB
testcase_21 AC 898 ms
7,928 KB
testcase_22 AC 876 ms
7,896 KB
testcase_23 AC 873 ms
7,968 KB
testcase_24 AC 830 ms
7,980 KB
testcase_25 AC 870 ms
7,964 KB
testcase_26 AC 955 ms
7,948 KB
testcase_27 AC 908 ms
7,868 KB
testcase_28 AC 917 ms
7,924 KB
testcase_29 AC 11 ms
7,516 KB
testcase_30 AC 12 ms
7,576 KB
testcase_31 AC 872 ms
7,892 KB
testcase_32 AC 872 ms
7,944 KB
testcase_33 AC 956 ms
7,992 KB
testcase_34 AC 957 ms
8,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 3000000000000000

struct combi{
	deque<mint> kaijou;
	deque<mint> kaijou_;
	
	combi(int n){
		kaijou.push_back(1);
		for(int i=1;i<=n;i++){
			kaijou.push_back(kaijou[i-1]*i);
		}
		
		mint b=kaijou[n].inv();
		
		kaijou_.push_front(b);
		for(int i=1;i<=n;i++){
			int k=n+1-i;
			kaijou_.push_front(kaijou_[0]*k);
		}
	}
	
	mint combination(int n,int r){
		if(r>n)return 0;
		mint a = kaijou[n]*kaijou_[r];
		a *= kaijou_[n-r];
		return a;
	}
	
	mint junretsu(int a,int b){
		mint x = kaijou_[a]*kaijou_[b];
		x *= kaijou[a+b];
		return x;
	}
	
	mint catalan(int n){
		return combination(2*n,n)/(n+1);
	}
	
};


int main(){
	combi C(500000);
	string s;
	cin>>s;
	int n = s.size();
	if(s.size()%2==1){
		cout<<0<<endl;
		return 0;
	}
	
	vector dp(n+1,vector<mint>(2,0));
	dp[0][0] = 1;
	dp[0][1] = 1;
	rep(i,n){
		vector ndp(n+1,vector<mint>(2,0));
		rep(j,n+1){
			rep(k,2){
				if(dp[j][k]==0)continue;
				rep(l,3){
					if(l==0){
						if(s[i]!='('&&s[i]!='.')continue;
						ndp[j+1][k] += dp[j][k];
					}
					if(l==1){
						if(s[i]!=')'&&s[i]!='.')continue;
						if(j==0)continue;
						ndp[j-1][k] += dp[j][k];
					}
					if(l==2){
						if(s[i]!='?'&&s[i]!='.')continue;
						if(k==0){
							ndp[j+1][k] += dp[j][k];
							ndp[j+1][1] += dp[j][k];
						}
						else{
							if(j==0)continue;
							ndp[j-1][k] += dp[j][k];
						}						
					}
					
				}
			}
			
		}
		swap(dp,ndp);
		
	}
	
	cout<<dp[0][1].val()<<endl;
	
	return 0;
}
0