QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#274588#5066. String-dle CountGFFFWA 648ms35444kbC++142.2kb2023-12-03 18:05:242023-12-03 18:05:25

Judging History

你现在查看的是最新测评结果

  • [2023-12-03 18:05:25]
  • 评测
  • 测评结果:WA
  • 用时:648ms
  • 内存:35444kb
  • [2023-12-03 18:05:24]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=30,maxs=1<<19|7,mod=1e9+7;
inline void inc(int &x,int y) {x+=y;if(x>=mod) x-=mod;}
inline int mul(int x,int y) {return 1LL*x*y%mod;}
inline int qw(int a,int b,int ans=1) {for(;b;b>>=1,a=mul(a,a)) if(b&1) ans=mul(ans,a);return ans;}
int ans,n,K,ct,bin[maxn],wh[maxn],cnt[maxn],mn[maxn],mx[maxn],can[maxn][26],up[maxn],has[maxn],dp[maxn][maxs];
char s[maxn],t[maxn];
void work()
{
    for(int i=0;i<26;++i) cnt[i]=0;
    for(int i=1;i<=K;++i)
    {
        int x=s[i]-'A';
        if(t[i]=='O')
        {
            ++cnt[x];
            for(int j=0;j<26;++j) can[i][j]=0;
            can[i][x]=1;
        }
        else
        {
            can[i][x]=0;
            if(t[i]=='x')
            {
                mx[x]=min(mx[x],cnt[x]);
                up[x]=1;
            }
            else ++cnt[x];
        }
    }
    for(int x=0;x<26;++x) mn[x]=max(mn[x],cnt[x]);
}
int main()
{
    scanf("%d%d",&n,&K);
    for(int i=bin[0]=1;i<=K;++i) bin[i]=bin[i-1]<<1;
    for(int i=1;i<=K;++i)
        for(int j=0;j<26;++j)
            can[i][j]=1;
    for(int i=0;i<26;++i) mn[i]=0,mx[i]=K;
    for(int i=1;i<=n;++i)
    {
        scanf("%s",s+1);
        scanf("%s",t+1);
        work();
    }
    for(int i=0;i<26;++i)
        if(mn[i]>mx[i])
            return puts("0"),0;
    for(int i=0;i<26;++i)
        for(int j=1;j<=mn[i];++j)
        {
            has[i]|=bin[ct];
            wh[ct]=i;
            ++ct;
            if(ct>K) return puts("0"),0;
        }
    if(ct>K) return puts("0"),0;
    const int mmx=(1<<ct)-1;
    dp[0][0]=1;
    for(int i=0;i<K;++i)
        for(int s=0;s<=mmx;++s)
            if(dp[i][s])
            {
                for(int c=0;c<ct;++c)
                    if((!(bin[c]&s))&&can[i+1][wh[c]])
                        inc(dp[i+1][s|bin[c]],dp[i][s]);
                for(int c=0;c<26;++c)
                    if((has[c]==(has[c]&s))&&!up[c]&&can[i+1][c])
                        inc(dp[i+1][s],dp[i][s]);
            }
    ans=dp[K][mmx];
    for(int i=0;i<26;++i)
        for(int j=1;j<=mn[i];++j)
            ans=mul(ans,qw(j,mod-2));
    cout<<ans<<endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3856kb

input:

2 5
CRANE
xx--x
NASAL
OOxOO

output:

21

result:

ok 1 number(s): "21"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3640kb

input:

1 5
BBBAA
xxxx-

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

2 5
ABCDE
-xxxx
ABCDE
xxxxx

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3788kb

input:

1 3
ABC
---

output:

2

result:

ok 1 number(s): "2"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3784kb

input:

1 15
AAAAAAAAAAAAAAB
-xxxxxxxxxxxxxx

output:

918547951

result:

ok 1 number(s): "918547951"

Test #6:

score: 0
Accepted
time: 1ms
memory: 3700kb

input:

1 15
AAAAAAAAAAAAAAA
-xxxxxxxxxxxxxx

output:

0

result:

ok 1 number(s): "0"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

1 1
K
x

output:

25

result:

ok 1 number(s): "25"

Test #8:

score: 0
Accepted
time: 299ms
memory: 20060kb

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: 603ms
memory: 35432kb

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: 599ms
memory: 35444kb

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: 614ms
memory: 35320kb

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: 614ms
memory: 32848kb

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: 599ms
memory: 34932kb

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: 3828kb

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: 648ms
memory: 35320kb

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: 0ms
memory: 3856kb

input:

1 3
PYP
xxx

output:

13824

result:

ok 1 number(s): "13824"

Test #17:

score: 0
Accepted
time: 0ms
memory: 3644kb

input:

3 3
ENP
xxx
PJK
xxx
BZL
xxx

output:

5832

result:

ok 1 number(s): "5832"

Test #18:

score: 0
Accepted
time: 0ms
memory: 3600kb

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: 3740kb

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: 0ms
memory: 3832kb

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'