QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#533102#4436. Link with Bracket Sequence IIxuzhihaodedie#WA 314ms5672kbC++201.5kb2024-08-25 17:18:272024-08-25 17:18:28

Judging History

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

  • [2024-08-25 17:18:28]
  • 评测
  • 测评结果:WA
  • 用时:314ms
  • 内存:5672kb
  • [2024-08-25 17:18:27]
  • 提交

answer

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PII pair<int,int>
#define lson 2*p
#define rson 2*p+1
#define x first
#define y second
//#define endl "\n"
const int N=2e5+10;
const int mod=1e9+7;
int n,m;
int dp[505][505];
int a[N];
void solve() {
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	if(n&1) {
		cout<<0<<endl;
		return ;
	}
	for(int i=0;i<=n;i++) {
		for(int j=0;j<=n;j++) {
			dp[i][j]=0;
		}
	}
	for(int i=1;i<n;i++) {
		if(a[i]!=0&&a[i+1]!=0) {
			if(a[i]+a[i+1]==0&&a[i]>0) dp[i][i+1]=1;
			else dp[i][i+1]=0;
		} else if(!a[i]&&!a[i+1]) {
			dp[i][i+1]=m;
		} else {
			dp[i][i+1]=1;
		}
	}
	for(int len=4;len<=n;len+=2) {
		for(int i=1;i+len-1<=n;i++) {
			int j=i+len-1;
			for(int k=i+3;k<=j-2;k+=2) {
				if(a[i]+a[k]==0&&a[i]>0) dp[i][j]=(dp[i][j]+dp[i+1][k-1]*dp[k+1][j]%mod)%mod;
				else if(!a[i]&&!a[k]) dp[i][j]=(dp[i][j]+dp[i+1][k-1]*dp[k+1][j]%mod*m%mod)%mod;
				else dp[i][j]=(dp[i][j]+dp[i+1][k-1]*dp[k+1][j]%mod)%mod;
			}
			dp[i][j]=(dp[i][j]+dp[i][i+1]*dp[i+2][j]%mod)%mod;
			if(a[i]!=0&&a[j]!=0) {
				if(a[i]+a[j]==0&&a[i]>0) dp[i][j]=(dp[i][j]+dp[i+1][j-1])%mod;
			} else if(a[i]==0&&a[j]==0) {
				dp[i][j]=(dp[i][j]+dp[i+1][j-1]*m%mod)%mod;
			} else {
				dp[i][j]=(dp[i][j]+dp[i+1][j-1])%mod;
			}
		}
	}
	cout<<dp[1][n]<<endl;
}
signed main() {
	// ios::sync_with_stdio(false);
	// cin.tie(0);
//	cout.tie(0);
	int T=1;
	cin>>T;
	while(T--) {
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 314ms
memory: 5672kb

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:

6
0
185
0
1750
76083727
567438125
80226986
392448557
507821717
833673146
709451673
963504485
309111842
394548816
711261617
671177092
227852148
343052576
776801212

result:

wrong answer 1st lines differ - expected: '0', found: '6'