QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#482315 | #4222. 题 | bai_hong | 100 ✓ | 705ms | 723680kb | C++14 | 2.3kb | 2024-07-17 18:53:30 | 2024-07-17 18:53:30 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
const int mod=1e9+7;
using namespace std;
inline int read(){
int x=0,f=1; char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar())
if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar())
x=(x<<1)+(x<<3)+(ch^48);
return x*f;
}
int T,n,f[2][21][21][21][21][21][21],cur; char ch[60];
inline void sol(int x){
for (int i=0;i<=n;i++)
for (int j=0;i+j<=n;j++)
for (int k=0;i+j+k<=n;k++)
for (int a=0;i+j+k+a<=n;a++)
for (int b=0;i+j+k+a+b<=n;b++)
for (int c=0;i+j+k+a+b+c<=n;c++)
switch (x){
case 1:{
f[cur][i][j][k][a][b][c]+=
(i ? f[cur^1][i-1][j][k][a][b][c]:0)+
(a ? f[cur^1][i][j+1][k][a-1][b][c]*(j+1)%mod:0)+
f[cur^1][i][j][k][a][b][c+1]*(c+1)%mod;
f[cur][i][j][k][a][b][c]%=mod;
break;
}
case 2:{
f[cur][i][j][k][a][b][c]+=
(j ? f[cur^1][i][j-1][k][a][b][c]:0)+
(c ? f[cur^1][i][j][k+1][a][b][c-1]*(k+1)%mod:0)+
f[cur^1][i][j][k][a][b+1][c]*(b+1)%mod;
f[cur][i][j][k][a][b][c]%=mod;
break;
}
case 3:{
f[cur][i][j][k][a][b][c]+=
(k ? f[cur^1][i][j][k-1][a][b][c]:0)+
(b ? f[cur^1][i+1][j][k][a][b-1][c]*(i+1)%mod:0)+
f[cur^1][i][j][k][a+1][b][c]*(a+1)%mod;
f[cur][i][j][k][a][b][c]%=mod;
break;
}
}
}
inline void clear(){
// memset(f[cur],0,sizeof(f[cur]));
for (int i=0;i<=n+1;i++)
for (int j=0;i+j<=n+1;j++)
for (int k=0;i+j+k<=n+1;k++)
for (int a=0;i+j+k+a<=n+1;a++)
for (int b=0;i+j+k+a+b<=n+1;b++)
for (int c=0;i+j+k+a+b+c<=n+1;c++)
f[cur][i][j][k][a][b][c]=0;
}
inline void debug(){
for (int i=0;i<=n;i++)
for (int j=0;i+j<=n;j++)
for (int k=0;i+j+k<=n;k++)
for (int a=0;i+j+k+a<=n;a++)
for (int b=0;i+j+k+a+b<=n;b++)
for (int c=0;i+j+k+a+b+c<=n;c++)
printf("f[%d][%d][%d][%d][%d][%d]=%d\n",i,j,k,a,b,c,f[cur][i][j][k][a][b][c]);
puts("-----------------------");
}
signed main(){
for (T=read();T--;){
n=read(),scanf("%s",ch+1);
cur=0,clear();
f[cur][0][0][0][0][0][0]=1;
int fnc=1;
for (int i=1;i<=3*n;i++){
if (i<=n) fnc=fnc*i%mod;
cur^=1,clear();
if (ch[i]=='1'||ch[i]=='0') sol(1);
if (ch[i]=='2'||ch[i]=='0') sol(2);
if (ch[i]=='3'||ch[i]=='0') sol(3);
// debug();
}
printf("%lld\n",f[cur][0][0][0][0][0][0]*fnc%mod);
}
return 0;
}
详细
Test #1:
score: 10
Accepted
time: 0ms
memory: 24408kb
input:
5 1 123 1 100 1 000 1 300 1 010
output:
0 1 3 1 1
result:
ok 5 lines
Test #2:
score: 10
Accepted
time: 0ms
memory: 34620kb
input:
5 1 303 2 000320 2 002000 2 002020 2 020020
output:
0 36 60 12 12
result:
ok 5 lines
Test #3:
score: 10
Accepted
time: 0ms
memory: 51076kb
input:
5 2 110133 3 200010000 3 002002200 3 300000000 3 000000130
output:
0 5940 540 15120 7560
result:
ok 5 lines
Test #4:
score: 10
Accepted
time: 0ms
memory: 94048kb
input:
5 5 000000000000000 4 000000000000 3 000000000 2 000000 1 000
output:
864823720 29937600 45360 180 3
result:
ok 5 lines
Test #5:
score: 10
Accepted
time: 7ms
memory: 149460kb
input:
5 6 000121310223223210 7 033221120002010100230 7 000003020000010302010 7 000010002020302300100 7 030100002033300000000
output:
26853120 152413083 939384999 4309685 970165754
result:
ok 5 lines
Test #6:
score: 10
Accepted
time: 12ms
memory: 251776kb
input:
5 9 120332011311030220200103301 10 200003200103011232000202201120 10 000000201330030030101000003000 10 020000002032000000200000100002 10 100200322001000000320000002010
output:
963757075 290911546 487693965 730680478 984422198
result:
ok 5 lines
Test #7:
score: 10
Accepted
time: 58ms
memory: 377056kb
input:
5 13 000000000000000000000000000000000000000 12 000000000000000000000000000000000000 11 000000000000000000000000000000000 10 000000000000000000000000000000 9 000000000000000000000000000
output:
856865849 574346463 607449787 883895867 88660419
result:
ok 5 lines
Test #8:
score: 10
Accepted
time: 283ms
memory: 542632kb
input:
5 15 331110203302222220331213331310312220103030021 16 001301022200100032010330002213000300220033210033 16 020002030002000330003200030010000000000100002300 16 320000001003222000003000003000300010323113200020 16 000203000000000000010100000000000000002000210000
output:
70336694 482512438 740138646 212387388 427674884
result:
ok 5 lines
Test #9:
score: 10
Accepted
time: 538ms
memory: 662336kb
input:
5 17 221001103220113003322101120223031133120301212031002 18 201000020000000010323100000333030002012000213100030001 18 013203020100001021200030003102000130000002330303302120 18 010003030200000200100000002000000000000302000203103300 18 000001000132020000200321023010000000000000000132210300
output:
821788453 589132243 303959134 648206569 571580782
result:
ok 5 lines
Test #10:
score: 10
Accepted
time: 705ms
memory: 723680kb
input:
5 18 331110100201233220121012022130200011112133012123201012 19 221011310310012302220013020123002132313030023020101110230 19 202000300003001300011000011021320001000300320020302022103 19 010030200000000000300300310000001302002000010230000330020 19 000000000000031000000000131200020001000020000001020000...
output:
171958822 242716134 229925968 914555153 59496792
result:
ok 5 lines
Extra Test:
score: 0
Extra Test Passed