QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#333920 | #5066. String-dle Count | C1942huangjiaxu | TL | 147ms | 44904kb | C++14 | 1.5kb | 2024-02-20 20:02:08 | 2024-02-20 20:02:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int P=1e9+7;
int n,m,ct[26],ac[26],c[26],dp[1<<19],f[20][1<<19];
bool ban[19][26],bn[26],lim[26];
char s[19],t[19];
inline void Add(int &x,int y){
if((x+=y)>=P)x-=P;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<26;++i)ct[i]=0;
for(int i=0;i<m;++i)ac[i]=-1;
for(int i=1;i<=n;++i){
scanf("%s%s",s,t);
memset(c,0,sizeof(c));
memset(bn,false,sizeof(bn));
for(int j=0;j<m;++j){
int u=s[j]-'A';
if(t[j]=='O'){
if(~ac[j]&&ac[j]!=u)return puts("0"),0;
ac[j]=u,++c[u];
continue;
}
ban[j][u]=true;
if(t[j]=='-'){
if(bn[u])return puts("0"),0;
++c[u];
}else bn[u]=true;
}
for(int j=0;j<26;++j){
if(bn[j]&&(c[j]<ct[j]||lim[j]&&c[j]!=ct[j]))return puts("0"),0;
if(bn[j])lim[j]=true,ct[j]=c[j];
else ct[j]=max(ct[j],c[j]);
}
}
int sum=0;
for(int i=0;i<26;++i)if(~ac[i]&&ban[i][ac[i]])return puts("0"),0;
for(int i=0;i<26;++i)sum+=ct[i];
if(sum>m)return puts("0"),0;
dp[0]=1;
for(int i=0;i<26;++i){
memset(f,0,sizeof(f));
for(int S=0;S<1<<m;++S)f[0][S]=dp[S],dp[S]=0;
for(int j=0;j<m;++j)if(!ban[j][i]&&(ac[j]==-1||ac[j]==i)){
for(int S=0;S<1<<m;++S)if(!(S>>j&1)){
for(int k=0;k<m;++k)if(f[k][S]){
Add(f[k+1][S|1<<j],f[k][S]);
}
}
}
for(int S=0;S<1<<m;++S){
if(lim[i])dp[S]=f[ct[i]][S];
else{
for(int j=ct[i];j<=m;++j)Add(dp[S],f[j][S]);
}
}
}
printf("%d\n",dp[(1<<m)-1]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 62ms
memory: 44904kb
input:
2 5 CRANE xx--x NASAL OOxOO
output:
21
result:
ok 1 number(s): "21"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3664kb
input:
1 5 BBBAA xxxx-
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
2 5 ABCDE -xxxx ABCDE xxxxx
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 53ms
memory: 44820kb
input:
1 3 ABC ---
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 147ms
memory: 44876kb
input:
1 15 AAAAAAAAAAAAAAB -xxxxxxxxxxxxxx
output:
918547951
result:
ok 1 number(s): "918547951"
Test #6:
score: 0
Accepted
time: 118ms
memory: 44876kb
input:
1 15 AAAAAAAAAAAAAAA -xxxxxxxxxxxxxx
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 70ms
memory: 44844kb
input:
1 1 K x
output:
25
result:
ok 1 number(s): "25"
Test #8:
score: -100
Time Limit Exceeded
input:
19 19 ZAZZZAZZZZZZZZZZAAZ x-xxxxxxxxxxxxxxxxx ZBZBZZBZZZZBZZZZBZZ x-xxxxxxxxxxxxxxxxx CZZCZZCZCZZCZZZCZZZ -xxxxxxxxxxxxxxxxxx ZDZZDZDZZZZZZZZZZZZ x-xxxxxxxxxxxxxxxxx ZZZZEEZEZZEEZZZZZZZ xxxx-xxxxxxxxxxxxxx ZZZZZFZZZZZZZZZZZZF xxxxx-xxxxxxxxxxxxx ZZGGZZZZZZZZGGGZZGZ xx-xxxxxxxxxxxxxxxx HHHHZHZZZZHHZZ...