QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#281529 | #5066. String-dle Count | Doqe | WA | 316ms | 40664kb | C++14 | 2.3kb | 2023-12-10 11:12:17 | 2023-12-10 11:12:18 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int P=1e9+7;
int F[21][1<<19];
char s[26],t[26];
int cnt[26],n,k;
int lst[26];
char ans[26];
int ban[26],ok[1<<19];
int rl[26],rr[26];
void jiao(int&l,int&r,int x,int y)
{
l=max(l,x),r=min(r,y);
}
__inline void ADD(int&x,int y){x=(x+y>=P)?(x+y-P):(x+y);}
__inline bool ck(int x){return !(x&(x+1));}
int c[26];
int main()
{
cin>>n>>k;
for(int i=0;i<26;++i)rl[i]=0,rr[i]=k;
while(n--)
{
cin>>s+1>>t+1;
memset(lst,0,sizeof lst);
memset(cnt,0,sizeof cnt);
for(int i=1;i<=k;++i)
{
int o=s[i]-'A';
if(t[i]=='O')ans[i]=s[i],ban[i]|=(1<<26)-1-(1<<o);
else if(t[i]=='x')
{
ban[i]|=1<<o;
lst[o]=1;
}
else if(t[i]=='-')
{
if(lst[o])return cout<<"0",0;
++cnt[o];
ban[i]|=1<<o;
}
}
for(int i=0;i<26;++i)
if(!lst[i])jiao(rl[i],rr[i],cnt[i],k);
else jiao(rl[i],rr[i],cnt[i],cnt[i]);
}
for(int i=0;i<26;++i)if(rl[i]>rr[i])return cout<<"0",0;
for(int i=1;i<26;++i)c[i]=c[i-1]+rl[i-1];
int K=c[25]+rl[25];
for(int S=0;S<(1<<K);++S)
{
ok[S]=1;
for(int i=0;i<26;++i)
if(!ck(S>>c[i]&(1<<rl[i])-1)){ok[S]=0;break;}
// cerr<<S<<": "<<ok[S]<<endl;
}
F[1][0]=1;
// cerr<<"SUC\n";
for(int i=1;i<=k;++i)
{
vector<int>u1,u2;
for(int j=0;j<26;++j)if(!(ban[i]>>j&1))(rl[j]==rr[j]?u1:u2).push_back(j);
// for(auto k:u1)cerr<<k<<"_";cerr<<endl;
// for(auto k:u2)cerr<<k<<"_";cerr<<endl;
for(int S=0;S<(1<<K);++S)if(ok[S]&&F[i][S])
{
// cerr<<"FIND: F "<<i<<","<<S<<" "<<F[i][S]<<endl;
for(auto j:u1)
{
int T=S>>c[j]&(1<<rl[j])-1;
if(T==(1<<rl[j])-1)continue;
T=(T<<1|1)&(1<<rl[j])-1;
T=(T<<c[j])|S;
ADD(F[i+1][T],F[i][S]);
}
for(auto j:u2)
{
int T=S>>c[j]&(1<<rl[j])-1;
T=(T<<1|1)&(1<<rl[j])-1;T=(T<<c[j])|S;
ADD(F[i+1][T],F[i][S]);
}
}
}
cout<<F[k+1][(1<<K)-1]<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7736kb
input:
2 5 CRANE xx--x NASAL OOxOO
output:
21
result:
ok 1 number(s): "21"
Test #2:
score: 0
Accepted
time: 0ms
memory: 5676kb
input:
1 5 BBBAA xxxx-
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5588kb
input:
2 5 ABCDE -xxxx ABCDE xxxxx
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 1ms
memory: 7768kb
input:
1 3 ABC ---
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 1ms
memory: 7772kb
input:
1 15 AAAAAAAAAAAAAAB -xxxxxxxxxxxxxx
output:
918547951
result:
ok 1 number(s): "918547951"
Test #6:
score: 0
Accepted
time: 1ms
memory: 7724kb
input:
1 15 AAAAAAAAAAAAAAA -xxxxxxxxxxxxxx
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 1ms
memory: 7960kb
input:
1 1 K x
output:
25
result:
ok 1 number(s): "25"
Test #8:
score: 0
Accepted
time: 155ms
memory: 25164kb
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: 316ms
memory: 39940kb
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: 306ms
memory: 40212kb
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: 183ms
memory: 40312kb
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: 171ms
memory: 37768kb
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: 180ms
memory: 39576kb
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: 1ms
memory: 7720kb
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: 308ms
memory: 40664kb
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: 7984kb
input:
1 3 PYP xxx
output:
13824
result:
ok 1 number(s): "13824"
Test #17:
score: 0
Accepted
time: 1ms
memory: 7740kb
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: 7672kb
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: 1ms
memory: 7728kb
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: -100
Wrong Answer
time: 1ms
memory: 7840kb
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:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'