#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,i,j,ii,jj,zx,xc,mod=1000000007LL,dp[303][303][303],tes,t,II,k,kk,f[8],bl[603];
void rec(long long q, bool bo){
if(f[1]<0||f[2]<0||f[3]<0) return;
long long ZX=zx;
if(q==4){
if(bo==0) return;
dp[i][j][k]+=dp[f[1]][f[2]][f[3]]*zx;dp[i][j][k]%=mod;
return;
}
if(q==1){
if(f[1]+f[3]==0){
rec(q+1,bo);
zx=ZX;
return;
}
zx*=f[1];zx%=mod;
f[1]--;
rec(q+1,1);
zx=ZX;
f[1]++;
//
zx*=f[3];zx%=mod;
f[3]--;f[2]++;
rec(q+1,bo);
zx=ZX;
f[3]++;f[2]--;
return;
}
if(q==2){
if(f[1]+f[2]==0){
rec(q+1,bo);
zx=ZX;
return;
}
zx*=f[1];zx%=mod;
f[1]--;f[3]++;
rec(q+1,bo);
zx=ZX;
f[1]++;f[3]--;
//
zx*=f[2];zx%=mod;
f[2]--;
rec(q+1,1);
zx=ZX;
f[2]++;
return;
}
if(q==3){
if(f[2]+f[3]==0){
rec(q+1,bo);
zx=ZX;
return;
}
zx*=f[2];zx%=mod;
f[2]--;f[1]++;
rec(q+1,bo);
zx=ZX;
f[2]++;f[1]--;
//
zx*=f[3];zx%=mod;
f[3]--;
rec(q+1,1);
zx=ZX;
f[3]++;
return;
}
}
int main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>a>>tes;
dp[0][0][0]=1;
for(II=1; II<=100; II++){
for(i=0; i<=II; i++){
for(j=0; j<=II-i; j++){
k=II-i-j;
f[1]=i;f[2]=j;f[3]=k;zx=1;
rec(1,0);
}
}
}
for(t=1; t<=tes; t++){
f[1]=0;f[2]=0;f[3]=0;
for(i=0; i<=a*6; i++){
bl[i]=0;
}
for(i=1; i<=3; i++){
for(j=1; j<=2*a; j++){
cin>>c;
if(bl[c]==0){
bl[c]=i;
}else{
if(bl[c]==1&&i==2){
f[1]++;
}
if(bl[c]==2&&i==3){
f[2]++;
}
if(bl[c]==1&&i==3){
f[3]++;
}
}
}
}
cout<<dp[f[1]][f[2]][f[3]]<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
12740 KB |
Output is correct |
2 |
Correct |
34 ms |
12720 KB |
Output is correct |
3 |
Correct |
37 ms |
12696 KB |
Output is correct |
4 |
Correct |
44 ms |
12692 KB |
Output is correct |
5 |
Incorrect |
37 ms |
12732 KB |
Output isn't correct |
6 |
Incorrect |
35 ms |
12740 KB |
Output isn't correct |
7 |
Incorrect |
35 ms |
12720 KB |
Output isn't correct |
8 |
Incorrect |
39 ms |
12784 KB |
Output isn't correct |
9 |
Incorrect |
35 ms |
12756 KB |
Output isn't correct |
10 |
Incorrect |
35 ms |
12740 KB |
Output isn't correct |