QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#114487#4436. Link with Bracket Sequence IILiufWA 484ms5272kbC++201.0kb2023-06-22 10:31:182023-06-22 10:31:18

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-22 10:31:18]
  • 评测
  • 测评结果:WA
  • 用时:484ms
  • 内存:5272kb
  • [2023-06-22 10:31:18]
  • 提交

answer

#include<bits/stdc++.h>

#define endl '\n'
#define pii pair<int, int>
#define int long long

using namespace std;

const int mod=1e9+7;

void solve(){
	int n,m;
	cin>>n>>m;

	vector<int>a(n+1);
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}

	vector dp(n+10,vector<int>(n+10,-1));

	function<int(int,int)>dfs=[&](int l,int r){
		if((r-l+1)&1)return 0ll;
		if(l>r)return 1ll;
		if(dp[l][r]!=-1)return dp[l][r];
		int ans=0;
		if(a[l]>0){
			for(int i=l+1;i<=r;i+=2){
				if(a[i]<0||!a[i]){
					ans+=dfs(l+1,i-1)*dfs(i+1,r)%mod;
					ans%=mod;
				} 
			}
		} else if(!a[l]){
			for(int i=l+1;i<=r;i+=2){
				if(!a[i]){
					ans+=m*dfs(l+1,i-1)%mod*dfs(i+1,r)%mod;
					ans%=mod;
				} else if(a[i]<0){
					ans+=dfs(l+1,i-1)*dfs(i+1,r)%mod;
					ans%=mod;
				}
			}
		}

		return dp[l][r]=ans;
	};

	cout<<dfs(1,n)%mod<<endl;
	// cout<<1<<endl;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int t;
	cin>>t;

	while(t--){
		solve();
	}

	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 484ms
memory: 5272kb

input:

20
10 1
1 -1 0 -1 -1 1 -1 1 0 0
10 2
0 1 1 -2 1 -2 -1 1 -2 1
8 5
0 0 4 0 0 2 -2 0
9 5
0 0 0 -3 0 0 0 0 0
8 5
0 1 0 0 0 0 0 0
498 249013689
239722195 0 0 0 -59682797 187213467 0 0 220688278 0 0 -133178217 165866643 -165866643 216987003 55229518 -55229518 -216987003 0 82546192 0 0 0 0 -62330427 -19687...

output:

0
0
75
0
1125
984267258
109218678
571952022
288159326
14438262
1
55416571
307794316
686930163
248163740
867480547
155641228
227852148
343052576
776801212

result:

wrong answer 6th lines differ - expected: '469841384', found: '984267258'