QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#69918#4436. Link with Bracket Sequence IIHeinzWA 1152ms5532kbC++20921b2023-01-03 14:26:212023-01-03 14:26:24

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-03 14:26:24]
  • 评测
  • 测评结果:WA
  • 用时:1152ms
  • 内存:5532kb
  • [2023-01-03 14:26:21]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=505,P=1e9+7;
int n,m;
int a[N];
int f[N][N];
int dp[N][N];
int main()
{
	int T;scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
		}
		for(int i=1;i<=n;i++){
			for(int j=i;j<=n;j++)
				dp[i][j]=f[i][j]=0;
		}
		for(int i=2;i<=n;i++)
		{
			for(int l=1;l+i-1<=n;l++)
			{
				int r=l+i-1;
				int num;
				if(a[l])
				{
					if(a[r]&&abs(a[r])!=abs(a[l]))num=0;
					else num=1;
				}else {
					if(a[r])num=1;
					else num=m;
				}
				if(i==2)f[l][r]=num;
				else f[l][r]=1ll*dp[l+1][r-1]*num%P;
				dp[l][r]=f[l][r];
				for(int k=l+1;k<=r;k++)
				{
					dp[l][r]=(dp[l][r]+1ll*dp[l][k-1]*f[k][r]%P)%P;	
				}
//				printf("[%d][%d]:%d f:%d num:%d\n",l,r,dp[l][r],f[l][r],num);
			}
		}
		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: 1152ms
memory: 5532kb

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:

42
1
160
0
1750
794099921
796396708
180786104
345214555
36228136
1
646409125
790867257
347678716
74014753
960399457
951689409
227852148
343052576
776801212

result:

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