QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#402905 | #1286. Ternary String Counting | Diu | WA | 2ms | 3896kb | C++14 | 1.6kb | 2024-05-01 17:26:01 | 2024-05-01 17:26:01 |
Judging History
answer
//
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5010,mod=1e9+7;
int T,n,m,l1[N],r1[N],l2[N],r2[N];
ll sl[N],sr[N],f[N][N];
int cx[N],cy[N];
void clr_f(int i,int k){
while(cx[i]<=k&&cx[i]<=cy[i]){
sl[i]=(sl[i]-f[i][cx[i]]+mod)%mod;
sr[cx[i]]=(sr[cx[i]]-f[i][cx[i]]+mod)%mod;
f[i][cx[i]]=0;
++cx[i];
}
}
void clr_b(int i,int k){
while(cy[i]>=k&&cx[i]<=cy[i]){
sl[i]=(sl[i]-f[i][cy[i]]+mod)%mod;
sr[cy[i]]=(sr[cy[i]]-f[i][cy[i]]+mod)%mod;
f[i][cy[i]]=0;
--cy[i];
}
}
signed main(){
scanf("%d",&T);
for(;T--;){
scanf("%d%d",&n,&m);
for(int i=0;i<=n;i++){
sl[i]=sr[i]=0;
cx[i]=l1[i]=l2[i]=0;
cy[i]=i,r1[i]=r2[i]=i-1;
for(int j=0;j<=i;j++)f[i][j]=0;
}
for(int i=1,l,r,x;i<=m;i++){
scanf("%d%d%d",&l,&r,&x);
if(x==1){
r1[r]=min(r1[r],l-1);
}else if(x==2){
l1[r]=max(l1[r],l);
r2[r]=min(r2[r],l-1);
}else{
l2[r]=max(l2[r],l);
}
}
f[0][0]=3;
sl[0]=sr[0]=3;
for(int i=2;i<=n;i++){
for(int j=0;j+1<i;j++){
f[i-1][j]=(sl[j]+sr[j])%mod;
sl[i-1]=(sl[i-1]+f[i-1][j])%mod;
sr[j]=(sr[j]+f[i-1][j])%mod;
}
for(int j=0;j<l1[i];j++)clr_f(j,j);
for(int j=l1[i];j<=r1[i];j++)clr_f(j,l2[i]-1),clr_b(j,r2[i]+1);
for(int j=r1[i]+1;j<i;j++)clr_f(j,j);
// printf("work:%d\n",i);
// printf("%d %d %d %d\n",l1[i],r1[i],l2[i],r2[i]);
// for(int j=0;j<i;j++){
// for(int k=0;k<=j;k++)if(f[j][k])printf("%d %d %d\n",j,k,f[j][k]);
// }
}
int ans=0;
for(int i=0;i<n;i++)ans=(ans+sl[i])%mod;
printf("%d\n",ans);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3896kb
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: 3856kb
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'