QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#403352 | #1286. Ternary String Counting | cwfxlh | WA | 2ms | 7796kb | C++14 | 1.7kb | 2024-05-02 09:09:00 | 2024-05-02 09:09:01 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
using namespace std;
int T,n,m,v2[50003][2],v3[50003],k1,k2,k3,k4,k5,k6,k7,k8,k9,ans;
int dp[5003][5003],hsum[5003],lsum[5003];
int zzh;
int q[100003],lft,rgt;
void del(int X){
if(v3[X]!=0){
while(zzh<v3[X]){
hsum[zzh]=0;
for(int j=0;j<=n;j++){
lsum[j]=(lsum[j]-dp[zzh][j])%MOD;
dp[zzh][j]=0;
}
zzh++;
}
}
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;
for(int i=1;i<=n;i++){
v3[i]=0;
v2[i][0]=0;
v2[i][1]=i+1;
}
for(int i=1;i<=m;i++){
cin>>k1>>k2>>k3;
if(k3==1)v2[k2][1]=min(v2[k2][1],k1-1);
if(k3==2){
v2[k2][0]=max(v2[k2][0],k1);
v2[k2][1]=min(v2[k2][1],k1);
}
if(k3==3)v3[k2]=max(v3[k2],k1);
}
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++)dp[i][j]=0;
hsum[i]=lsum[i]=0;
}
zzh=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]);
rgt++;
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--)sol();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7796kb
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: 3772kb
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 0 0 0 90 0 0 0 0 0 0 0 0 0 0 0 0 6 0 0 0 0 0 0 0 6 0 0 0 0 0 0 0 54 0 0 0 2916 0 0 0 0 0 0 0 0 0 0 0 8748 0 0 0 0 0 0 4320 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 450 0 162 0 0 0 0 0 0 54 0 18 0 0 0 0 24 0 540 54 0 0 0 12 0 0 0 0 18 0 0 0 0 0 0 0 0 243 810 0 0 0 0 0 0 0 0 972 0 0 0 ...
result:
wrong answer 9th words differ - expected: '768', found: '0'