QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#108126#1286. Ternary String CountingyoungsystemWA 2ms3592kbC++202.7kb2023-05-23 17:18:082023-05-23 17:18:10

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:18:10]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3592kb
  • [2023-05-23 17:18:08]
  • 提交

answer

#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
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()
{
	ios::sync_with_stdio(false); 
	cin.tie(0);
	cout.tie(0);
	int t,n,m;
	int l,r,x;
	cin>>t;
	for(int greg=1;greg<=t;greg++)
	{
		cin>>n>>m;
		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;i++)
		{
			nl[i]=1;
			nr[i]=0;
			heh[i]=0;
			hel[i]=0; 
		}
		for(int i=1;i<=m;i++)
		{
			cin>>l>>r>>x;
			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%d\n",i); 
			for(int j=1;j<=i;j++)
			{
				for(int k=1;k<=i;k++)printf("%d ",dp[j][k]);
				printf("\n");
			}*/
			//for(int j=1;j<=i;j++)printf("%d %d\n",nl[j],nr[j]);
		}
		int ans=0;
		for(int i=1;i<=n;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];
			}
		}
		cout<<ans<<"\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3504kb

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: 3592kb

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
768
0
0
972
2916
0
6480
864
0
0
0
0
0
0
0
0
6
0
0
0
0
0
96
0
6
0
0
0
0
0
0
108
0
0
0
2916
0
0
0
0
0
0
0
0
0
0
324
8748
0
0
0
0
0
4320
0
0
0
18
0
0
0
0
0
0
0
0
0
0
0
1992
0
0
450
0
162
1656
0
0
0
0
54
0
18
0
0
0
0
744
0
1620
324
0
0
36
36
0
0
60
6
54
0
0
0
0
0
0
0
243
810
0
0
0
756...

result:

wrong answer 8th words differ - expected: '0', found: '768'