QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#333928 | #5066. String-dle Count | C1942huangjiaxu | WA | 45ms | 7976kb | C++14 | 1.5kb | 2024-02-20 20:15:05 | 2024-02-20 20:15:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int P=1e9+7;
int n,m,ct[26],ac[26],c[26],f[1<<19],pc[1<<19];
bool ban[19][26],bn[26],lim[26];
char s[19],t[19];
vector<int>va;
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]);
}
}
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)for(int j=1;j<=ct[i];++j)va.push_back(i);
if(va.size()>m)return puts("0"),0;
while(va.size()<m)va.push_back(26);
for(int i=1;i<1<<m;++i)pc[i]=pc[i>>1]+(i&1);
f[0]=1;
for(int S=0;S<(1<<m)-1;++S)if(f[S]){
int u=pc[S];
for(int i=0;i<m;++i)if(!(S>>i&1)){
if(i&&va[i]==va[i-1]&&!(S>>i-1&1))continue;
if(va[i]==26){
if(ac[u]!=-1)continue;
for(int j=0;j<26;++j)if(!lim[j]&&!ban[u][j])Add(f[S|1<<i],f[S]);
}else if(!ban[u][va[i]]&&(ac[u]==-1||ac[u]==va[i]))Add(f[S|1<<i],f[S]);
}
}
printf("%d\n",f[(1<<m)-1]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5864kb
input:
2 5 CRANE xx--x NASAL OOxOO
output:
21
result:
ok 1 number(s): "21"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
1 5 BBBAA xxxx-
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
2 5 ABCDE -xxxx ABCDE xxxxx
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 1ms
memory: 6000kb
input:
1 3 ABC ---
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 1ms
memory: 6044kb
input:
1 15 AAAAAAAAAAAAAAB -xxxxxxxxxxxxxx
output:
918547951
result:
ok 1 number(s): "918547951"
Test #6:
score: 0
Accepted
time: 1ms
memory: 6044kb
input:
1 15 AAAAAAAAAAAAAAA -xxxxxxxxxxxxxx
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 1ms
memory: 5996kb
input:
1 1 K x
output:
25
result:
ok 1 number(s): "25"
Test #8:
score: 0
Accepted
time: 45ms
memory: 7972kb
input:
19 19 ZAZZZAZZZZZZZZZZAAZ x-xxxxxxxxxxxxxxxxx ZBZBZZBZZZZBZZZZBZZ x-xxxxxxxxxxxxxxxxx CZZCZZCZCZZCZZZCZZZ -xxxxxxxxxxxxxxxxxx ZDZZDZDZZZZZZZZZZZZ x-xxxxxxxxxxxxxxxxx ZZZZEEZEZZEEZZZZZZZ xxxx-xxxxxxxxxxxxxx ZZZZZFZZZZZZZZZZZZF xxxxx-xxxxxxxxxxxxx ZZGGZZZZZZZZGGGZZGZ xx-xxxxxxxxxxxxxxxx HHHHZHZZZZHHZZ...
output:
182644947
result:
ok 1 number(s): "182644947"
Test #9:
score: 0
Accepted
time: 35ms
memory: 7904kb
input:
19 19 AZZZZZAZZZZZZAZZZZZ -xxxxxxxxxxxxxxxxxx ZZZBZZBBZZBBZZBZBZB xxx-xxxxxxxxxxxxxxx ZZZZZCCZZZZZZZZZZZZ xxxxx-xxxxxxxxxxxxx ZZZDZDZZZZZZDZZZZDZ xxx-xxxxxxxxxxxxxxx EZZZZZZZEZZZZZZZZZZ -xxxxxxxxxxxxxxxxxx ZZZZZZZZFFZZZZZZZZZ xxxxxxxx-xxxxxxxxxx ZZZZZZZZZZZZZGZZZZG xxxxxxxxxxxxx-xxxxx ZZHHZZHZZZHZZH...
output:
791604390
result:
ok 1 number(s): "791604390"
Test #10:
score: 0
Accepted
time: 40ms
memory: 7884kb
input:
19 19 ZAZAZZZZAZZZZZZAZZZ x-xxxxxxxxxxxxxxxxx ZBZZZBZZBZZZZZZZBZZ x-xxxxxxxxxxxxxxxxx ZZZZZZZCZCZZZZZZZZZ xxxxxxx-xxxxxxxxxxx ZDDDZZZDZZZZZZZZZZZ x-xxxxxxxxxxxxxxxxx ZEZZEEZZZZZEZZEZZZE x-xxxxxxxxxxxxxxxxx ZZZFZZZZFZZZZZFZFFZ xxx-xxxxxxxxxxxxxxx ZZZGGZZZZZZZZZZZZZG xxx-xxxxxxxxxxxxxxx ZHHZZZZZZZZZHZ...
output:
721023482
result:
ok 1 number(s): "721023482"
Test #11:
score: 0
Accepted
time: 41ms
memory: 7892kb
input:
19 19 ZZZAZZZAZZZAZZAAZZA xxx-xxxxxxxxxxxxxxx BBZZBZZBZZZBBBZZBZB -xxxxxxxxxxxxxxxxxx ZZCZCCZCCCZCCZCCZZC xx-xxxxxxxxxxxxxxxx ZDZZDZDDZDZZZDZDDZZ x-xxxxxxxxxxxxxxxxx EEZEZEZEZZZZEZEEEZE -xxxxxxxxxxxxxxxxxx ZZZFZFFFZFFFFZFFFFZ xxx-xxxxxxxxxxxxxxx ZGZGGZGZGZGGGZZGGGZ x-xxxxxxxxxxxxxxxxx ZHZZZHZHHZZHZZ...
output:
432987142
result:
ok 1 number(s): "432987142"
Test #12:
score: 0
Accepted
time: 41ms
memory: 7904kb
input:
19 19 ZAAZAZZAAZAZZZZZZAA x-xxxxxxxxxxxxxxxxx ZBZBBBZZBZZBZBBBZZB x-xxxxxxxxxxxxxxxxx CZCCCZZCCCZZZCCZZCC -xxxxxxxxxxxxxxxxxx DZDZDDDDZDDZZZZZZDD -xxxxxxxxxxxxxxxxxx ZEEEEEZZEEZEZZZZEZE x-xxxxxxxxxxxxxxxxx ZZFFZZZFZFFFZZFFZFF xx-xxxxxxxxxxxxxxxx ZZGZZZGZGZZGZZZGZGG xx-xxxxxxxxxxxxxxxx HZZZHZHZZZZZHZ...
output:
562846236
result:
ok 1 number(s): "562846236"
Test #13:
score: 0
Accepted
time: 43ms
memory: 7968kb
input:
19 19 AZZZZAZAZZZAZAZZAZZ -xxxxxxxxxxxxxxxxxx BZBBZBZZZBBZBZBBZBZ -xxxxxxxxxxxxxxxxxx ZCCCCCZCCZCCZZCZZCC x-xxxxxxxxxxxxxxxxx DDDDZDDZDZDZDDDZZDZ -xxxxxxxxxxxxxxxxxx EZZEZZEZZEEZEEZZEEZ -xxxxxxxxxxxxxxxxxx ZZZZFZZFZZZFZZZZFZZ xxxx-xxxxxxxxxxxxxx GGZGZGGZGGZGGZZZGGG -xxxxxxxxxxxxxxxxxx ZHZZHHHHHZZHHH...
output:
241578701
result:
ok 1 number(s): "241578701"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
26 19 AAAAAAAAAAAAAAAAAAA ------------------- BBBBBBBBBBBBBBBBBBB ------------------- CCCCCCCCCCCCCCCCCCC ------------------- DDDDDDDDDDDDDDDDDDD ------------------- EEEEEEEEEEEEEEEEEEE ------------------- FFFFFFFFFFFFFFFFFFF ------------------- GGGGGGGGGGGGGGGGGGG ------------------- HHHHHHHHHHHHHH...
output:
0
result:
ok 1 number(s): "0"
Test #15:
score: 0
Accepted
time: 33ms
memory: 7976kb
input:
19 19 ZAZZZZZZZZZZZZZZZZZ x-xxxxxxxxxxxxxxxxx ZZZZZZZZBZZZZZZZZZZ xxxxxxxx-xxxxxxxxxx ZZZZZZZZZZZZZZCZZZZ xxxxxxxxxxxxxx-xxxx ZZDZZZZZZZZZZZZZZZZ xx-xxxxxxxxxxxxxxxx ZZZZZZZZZZZZZEZZZZZ xxxxxxxxxxxxx-xxxxx ZZZZZZZZZZZZZZZFZZZ xxxxxxxxxxxxxxx-xxx ZZZZZZZZZZZGZZZZZZZ xxxxxxxxxxx-xxxxxxx ZZZZZZZZZZZZZZ...
output:
143269517
result:
ok 1 number(s): "143269517"
Test #16:
score: 0
Accepted
time: 1ms
memory: 5932kb
input:
1 3 PYP xxx
output:
13824
result:
ok 1 number(s): "13824"
Test #17:
score: 0
Accepted
time: 1ms
memory: 5904kb
input:
3 3 ENP xxx PJK xxx BZL xxx
output:
5832
result:
ok 1 number(s): "5832"
Test #18:
score: 0
Accepted
time: 1ms
memory: 5920kb
input:
5 3 LLK xxx WUQ xxx RDR xxx EUZ xxx FBU xxx
output:
3375
result:
ok 1 number(s): "3375"
Test #19:
score: 0
Accepted
time: 0ms
memory: 5808kb
input:
10 3 PKX xxx FBB xxx JSZ xxx RGB xxx BOS x-x OPG Oxx SHW xxx RDM xxx LHO xx- NBP xxx
output:
81
result:
ok 1 number(s): "81"
Test #20:
score: 0
Accepted
time: 1ms
memory: 5916kb
input:
15 3 DCJ xxx NCW xxx WDE xxx MAO xOO JXC xxx OBO xxO ALB -xx JWZ xxx QXK xxx FZW xxx VAJ xOx VHL xxx AZG -x- BWQ xxx GWB Oxx
output:
1
result:
ok 1 number(s): "1"
Test #21:
score: 0
Accepted
time: 1ms
memory: 5852kb
input:
20 3 FPR xxx FHF xxx WBH xxx XGA xx- QAC x-x JYS xxx ARR Oxx AAF Oxx LDY xxx ESD xxx QMB xxx EMS xxx UFT xx- JCK xxO YBH xxx KEN -xx FVL xxx PJP xxx DRB xxx UDL xxx
output:
1
result:
ok 1 number(s): "1"
Test #22:
score: 0
Accepted
time: 0ms
memory: 5924kb
input:
10000 3 XIX xxx RRY xxx RJB xxx XUT x-x BQB xxx RDP xxx EEX xxx DYJ xxx NHI -xx VMD xxx IVU xxO VBR xxx CJE Oxx BCF x-x WSS xxx ARP xxx HYR xxx YTO xxx NLJ -xx NMU -xO GUY x-x KAC xx- UYQ -xx OBU xxO ANA xOx HCK x-x GOX xxx ZNU xOO LSH xxx COM Oxx OAM xxx HNF xOx VOX xxx CZM Oxx KXM xxx MAN xx- RUG ...
output:
1
result:
ok 1 number(s): "1"
Test #23:
score: -100
Wrong Answer
time: 1ms
memory: 6000kb
input:
1 5 VYQWB x-xxx
output:
894432
result:
wrong answer 1st numbers differ - expected: '835275', found: '894432'