QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#50719#4436. Link with Bracket Sequence IIzzxzzx123WA 147ms5808kbC++172.2kb2022-09-28 20:22:472022-09-28 20:22:49

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-28 20:22:49]
  • 评测
  • 测评结果:WA
  • 用时:147ms
  • 内存:5808kb
  • [2022-09-28 20:22:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=510;
const ll mod=1e9+7;
int a[N];
ll dp[N][N];

ll get(int x,int y){
	if(x>y){
		return 1;
	}
	return dp[x][y];
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n,m;
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
		}
		memset(dp,-0x3f,sizeof dp);
		for(int i=1;i<n;i++){
			if(a[i]>0)
			{
				if((a[i]+a[i+1])==0)
				{
					dp[i][i+1]=1;
				}else if(!a[i+1])
				{
					dp[i][i+1]=1;
				}
			}else if(!a[i])
			{
				if(!a[i+1])
				{
					dp[i][i+1]=m;
				}else if(a[i+1]<0){
					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;
				ll x=get(i+1,j-1);
				if(a[i]<0)	continue;
				if(x>0){
					if(a[i]>0)
					{
						if((a[i]+a[j])==0)
						{
							if(dp[i][j]==-1)	dp[i][j]=0;
							dp[i][j]=(dp[i][j]+get(i+1,j-1))%mod;
						}else if(!a[i+1])
						{
							if(dp[i][j]==-1)	dp[i][j]=0;
							dp[i][j]=(dp[i][j]+get(i+1,j-1))%mod;
						}
					}else if(!a[i])
					{
						if(!a[j])
						{
							if(dp[i][j]==-1)	dp[i][j]=0;
							dp[i][j]=(dp[i][j]+get(i+1,j-1)*m%mod)%mod;
						}else if(a[j]<0){
							if(dp[i][j]==-1)	dp[i][j]=0;
							dp[i][j]=(dp[i][j]+get(i+1,j-1))%mod;
						}
					}					
				}
//				cout<<len<<" debug "<<i<<" "<<j<<" "<<dp[i][j]<<endl;								 
				for(int k=i+1;k<j;k+=2){
					//枚举中间的点
					ll x=get(i+1,k-1),y=get(k+1,j);
					if(x<0||y<0)
					{
						continue;
					}
					if(a[i]>0)
					{
						if((a[i]+a[k])==0)
						{
							if(dp[i][j]==-1)	dp[i][j]=0;
							dp[i][j]=(dp[i][j]+x*y%mod)%mod;
						}else if(!a[k])
						{
							if(dp[i][j]==-1)	dp[i][j]=0;
							dp[i][j]=(dp[i][j]+x*y%mod)%mod;
						}
					}else if(!a[i])
					{
						if(!a[k])
						{
							if(dp[i][j]==-1)	dp[i][j]=0;
							dp[i][j]=(dp[i][j]+x*m%mod*y%mod)%mod;
						}else if(a[j]<0){
							if(dp[i][j]==-1)	dp[i][j]=0;
							dp[i][j]=(dp[i][j]+x*y%mod)%mod;
						}
					}
				}
//				cout<<len<<" ceil  "<<i<<" "<<j<<" "<<dp[i][j]<<endl;	
			}
		}
		if(dp[1][n]==-1){
			dp[1][n]=0;
		}
		printf("%lld\n",dp[1][n]);
	}
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 147ms
memory: 5808kb

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:

-4485090715960753727
-4485090715960753727
-4485090715960753727
-4485090715960753727
-4485090715960753727
-4485090715960753727
-4485090715960753727
-4485090715960753727
-4485090715960753727
-4485090715960753727
-4485090715960753727
-4485090715960753727
-4485090715960753727
-4485090715960753727
-44850...

result:

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