QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#403367#1286. Ternary String CountingcwfxlhWA 2ms7780kbC++142.0kb2024-05-02 09:34:022024-05-02 09:34:04

Judging History

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

  • [2024-05-02 09:34:04]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:7780kb
  • [2024-05-02 09:34:02]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
using namespace std;
int T,n,m,v2[50003][2],v3[50003][2],k1,k2,k3,k4,k5,k6,k7,k8,k9,ans;
int dp[5003][5003],hsum[5003],lsum[5003];
int q[100003],lft,rgt,zz[50003];
void del(int X){
	for(int i=0;i<=X-2;i++){
		if(i>=v3[X][0]&&i<=v3[X][1])continue;
		hsum[i]=0;
		while(zz[i]<X){
			lsum[zz[i]]=(lsum[zz[i]]-dp[i][zz[i]])%MOD;
			dp[i][zz[i]]=0;
			zz[i]++;
		}
	}
	while(lft<=rgt){
		if(q[lft]>=v2[X][0])break;
		lsum[q[lft]]=0;
		for(int j=0;j<=n;j++){
			hsum[j]=(hsum[j]-dp[j][q[lft]])%MOD;
			dp[j][q[lft]]=0;
		}
		lft++;
	}
	while(lft<=rgt){
		if(q[rgt]<=v2[X][1])break;
		lsum[q[rgt]]=0;
		for(int j=0;j<=n;j++){
			hsum[j]=(hsum[j]-dp[j][q[rgt]])%MOD;
			dp[j][q[rgt]]=0;
		}
		rgt--;
	}
	return;
}
void add(int X,int Y,int val){
	hsum[X]=(hsum[X]+val)%MOD;
	lsum[Y]=(lsum[Y]+val)%MOD;
	dp[X][Y]=(dp[X][Y]+val)%MOD;
	return;
}
int stk[50003];
void sol(){
	cin>>n>>m;
	if(k9==89)cout<<n<<" "<<m<<endl;
	for(int i=1;i<=n;i++){
		v3[i][0]=0;
		v3[i][1]=i+1;
		v2[i][0]=0;
		v2[i][1]=i+1;
	}
	for(int i=1;i<=m;i++){
		cin>>k1>>k2>>k3;
		if(k9==89)cout<<k1<<" "<<k2<<" "<<k3<<endl;
		if(k3==1)v2[k2][1]=min(v2[k2][1],k1-1);
		if(k3==2){
			v2[k2][0]=max(v2[k2][0],k1);
			v3[k2][1]=min(v3[k2][1],k1-1);
		}
		if(k3==3)v3[k2][0]=max(v3[k2][0],k1);
	}
	for(int i=1;i<=n;i++){
		if(v2[i][0]>v2[i][1]||v3[i][0]>v3[i][1]){
			cout<<0<<endl;
			return;
		}
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++)dp[i][j]=0;
		hsum[i]=lsum[i]=0;
		zz[i]=0;
	}
	dp[0][0]=3;
	hsum[0]=lsum[0]=3;
	q[lft=rgt=50000]=0;
	del(1);
	for(int i=2;i<=n;i++){
		for(int j=0;j<i-1;j++)stk[j]=(hsum[j]+lsum[j])%MOD;
		for(int j=0;j<i-1;j++)add(j,i-1,stk[j]);
		q[++rgt]=i-1;
		del(i);
	}
	ans=0;
	for(int i=0;i<=n;i++)ans=(ans+hsum[i])%MOD;
	ans%=MOD;
	ans+=MOD;
	ans%=MOD;
	cout<<ans<<endl;
	return;
}
signed main(){
	ios::sync_with_stdio(false);
	cin>>T;
	while(T--){
		k9++;
		sol();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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
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
0
108
0
0
0
2916
0
0
0
0
0
0
0
0
0
0
324
8748
0
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
3 3
1 1 1
1 1 3
1 3 1
3
0
0
54
0
18
0
0
0
0
744
0
1620
324
0
0
36
36
0
0
60
6
54
0...

result:

wrong answer 89th words differ - expected: '0', found: '3'