QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#108122#1286. Ternary String CountingyoungsystemWA 2ms3840kbC++202.9kb2023-05-23 17:04:382023-05-23 17:04:42

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-23 17:04:42]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3840kb
  • [2023-05-23 17:04:38]
  • 提交

answer

#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
inline int read()
{
	int n=0,f=1,ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		n=n*10+ch-'0';
		ch=getchar();
	}
	return n*f;
}
int l1[5005],r1[5005];
int l2[5005],r2[5005];
int nl[5005],nr[5005];
int dp[5005][5005];
int heh[5005],hel[5005];
int main()
{
	int t,n,m;
	int l,r,x;
	t=read();
	for(int greg=1;greg<=t;greg++)
	{
		n=read();
		m=read();
		for(int i=1;i<=n;i++)
		{
			l1[i]=0;
			r1[i]=i-1;
			l2[i]=0;
			r2[i]=i-1;
		}
		for(int i=1;i<=n+1;i++)
		{
			nl[i]=1;
			nr[i]=0;
			heh[i]=0;
			hel[i]=0; 
		}
		for(int i=1;i<=m;i++)
		{
			l=read();
			r=read();
			x=read();
			if(x==3)
			{
				l1[r]=max(l1[r],l);
			}
			else if(x==2)
			{
				r1[r]=min(r1[r],(l-1));
				l2[r]=max(l2[r],l); 
			}
			else if(x==1)
			{
				r2[r]=min(r2[r],(l-1));
			}
		}
		//for(int i=1;i<=n;i++)printf("%d %d %d %d\n",l1[i],r1[i],l2[i],r2[i]);
		heh[1]=3;
		hel[1]=3;
		dp[1][1]=3;
		nl[1]=1;
		nr[1]=1;
		if(l1[1]>0||l2[1]>0)
		{
			printf("0\n");
			continue;
		}
		for(int i=2;i<=n;i++)
		{
			for(int j=0;j<=i-2;j++)
			{
				dp[j+1][i]=(heh[j+1]+hel[j+1]>=mod)?heh[j+1]+hel[j+1]-mod:heh[j+1]+hel[j+1];
			}
			nl[i]=1;
			nr[i]=i-1;
			for(int j=0;j<=i-2;j++)
			{
				heh[j+1]=(heh[j+1]+dp[j+1][i]>=mod)?heh[j+1]+dp[j+1][i]-mod:heh[j+1]+dp[j+1][i];
				hel[i]=(hel[i]+dp[j+1][i]>=mod)?hel[i]+dp[j+1][i]-mod:hel[i]+dp[j+1][i];
			}
			for(int j=1;j<=i;j++)
			{
				if(j-1<l2[i]||j-1>r2[i])
				{
					for(int sth=nl[j];sth<=nr[j];sth++)
					{
						//printf("del:%d %d\n",sth,j); 
						heh[sth]=(heh[sth]-dp[sth][j]>=0)?heh[sth]-dp[sth][j]:heh[sth]+mod-dp[sth][j];
						hel[j]=(hel[j]-dp[sth][j]>=0)?hel[j]-dp[sth][j]:hel[j]+mod-dp[sth][j];
						dp[sth][j]=0;
					}
					nl[j]=1;
					nr[j]=0;
				}
				else
				{
					for(int sth=nl[j];sth<l1[i]+1;sth++)
					{
						//printf("del:%d %d\n",sth,j);
						heh[sth]=(heh[sth]-dp[sth][j]>=0)?heh[sth]-dp[sth][j]:heh[sth]+mod-dp[sth][j];
						hel[j]=(hel[j]-dp[sth][j]>=0)?hel[j]-dp[sth][j]:hel[j]+mod-dp[sth][j];
						dp[sth][j]=0;
					}
					nl[j]=max(nl[j],l1[i]+1);
					for(int sth=r1[i]+2;sth<nr[j];sth++)
					{
						//printf("del:%d %d\n",sth,j);
						heh[sth]=(heh[sth]-dp[sth][j]>=0)?heh[sth]-dp[sth][j]:heh[sth]+mod-dp[sth][j];
						hel[j]=(hel[j]-dp[sth][j]>=0)?hel[j]-dp[sth][j]:hel[j]+mod-dp[sth][j];
						dp[sth][j]=0;
					}
					nr[j]=min(nr[j],r1[i]+1);
				}
			}
			/*printf("orz\n"); 
			for(int j=1;j<=i;j++)
			{
				for(int k=1;k<=i;k++)printf("%d ",dp[j][k]);
				printf("\n");
			}*/
		}
		int ans=0;
		for(int i=1;i<=n+1;i++)
		{
			for(int j=nl[i];j<=nr[i];j++)
			{
				ans=(ans+dp[j][i]>=mod)?ans+dp[j][i]-mod:ans+dp[j][i];
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3628kb

input:

4
1 0
2 0
3 0
5 2
1 3 3
4 5 1

output:

3
9
27
18

result:

ok 4 tokens

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3840kb

input:

741
5 3
1 5 3
3 4 2
1 4 3
4 3
2 4 2
1 4 1
2 3 3
10 3
9 10 2
3 6 3
1 9 1
3 4
2 3 2
1 3 2
2 3 3
1 3 3
10 4
6 6 1
9 10 2
4 8 3
4 10 3
6 3
1 4 3
2 4 2
2 2 2
4 3
1 4 1
1 1 2
2 3 1
5 3
4 5 2
4 5 1
1 4 3
9 3
2 3 2
1 9 2
2 4 2
4 3
1 3 3
2 3 2
1 2 3
8 4
5 8 1
4 8 1
3 5 3
1 3 3
9 3
4 5 1
1 5 3
3 8 2
8 3
5 7 2...

output:

90
0
0
0
24300
0
0
0
768
0
0
1548
3888
36
20466
2268
0
0
0
0
0
0
0
0
6
48
0
0
0
0
96
0
6
0
0
0
0
0
0
0
156
0
0
0
2916
0
0
0
0
0
0
0
0
0
0
324
8748
0
0
0
0
0
1728
4320
0
0
0
18
0
0
0
0
0
0
0
192
0
0
0
3900
0
0
450
0
162
3006
0
0
0
0
0
54
0
18
0
0
0
0
744
0
2172
612
0
0
36
48
0
0
168
6
534
0
0
0
0
0
0...

result:

wrong answer 12th words differ - expected: '972', found: '1548'