QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#26759#1286. Ternary String CountingWu_RenWA 4ms5964kbC++171.3kb2022-04-08 11:30:552022-04-29 04:23:41

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-29 04:23:41]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:5964kb
  • [2022-04-08 11:30:55]
  • 提交

answer

#include <bits/stdc++.h>
const int mod=1e9+7;
using namespace std;
int n,m,l[5010],r[5010],R[5010],C[5010],f[5010][5010],lk[5010],rk[5010],lj[5010],rj[5010];
void qmo(int &x){
	x+=(x>>31)&mod;
} 
void add(int x,int y,int w){
	qmo(w);
	qmo(f[x][y]+=w-mod);
	qmo(R[x]+=w-mod);
	qmo(C[y]+=w-mod);
}
void clr(int j,int lk,int rk){
	while(l[j]<=r[j]&&l[j]<lk) add(j,l[j],mod-f[j][l[j]]),l[j]++;
	while(l[j]<=r[j]&&r[j]>rk) add(j,r[j],mod-f[j][r[j]]),r[j]--;
}
void sol(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<=n;i++) R[i]=C[i]=0,lk[i]=lj[i]=l[i]=0,rk[i]=rj[i]=r[i]=n;
	for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) f[i][j]=0;
	add(0,0,1);
	for(int i=1,l,r,x;i<=m;i++){
		scanf("%d%d%d",&l,&r,&x);
		if(x==1) rj[r]=min(rj[r],l-1);
		if(x==3) lk[r]=max(lk[r],l);
		if(x==2) rk[r]=min(rk[r],l-1),lj[r]=max(lj[r],l);
	}
	for(int i=2;i<=n;i++){
		for(int k=0;k<i-1;k++) add(i-1,k,C[k]); 
		for(int j=1;j<i-1;j++) add(i-1,j,R[j]);
		for(int j=0;j<i;j++){
			if(j<lj[i]||rj[i]<j) clr(j,1,0);
			else clr(j,lk[i],rk[i]);
		}
//		for(int j=0;j<i;j++) for(int k=0;k<=j;k++) if(f[j][k]) printf("f[%d][%d][%d]=%d\n",i,j,k,f[j][k]);
	}
	int ans=0;
	for(int j=1;j<=n;j++) ans=(ans+6ll*R[j])%mod;
	ans=(ans+3ll*R[0])%mod;
	printf("%d\n",ans); 
}
int main(){
	int _;
	scanf("%d",&_);
	while(_--) sol();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 3908kb

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: 0ms
memory: 5964kb

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
3
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
4374
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
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
0
243
...

result:

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