QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#377163#5066. String-dle CountInfinityNS#TL 685ms98272kbC++144.2kb2024-04-04 23:34:032024-04-04 23:34:03

Judging History

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

  • [2024-04-04 23:34:03]
  • 评测
  • 测评结果:TL
  • 用时:685ms
  • 内存:98272kb
  • [2024-04-04 23:34:03]
  • 提交

answer

#pragma("unroll-loops")
#include<bits/stdc++.h>

#define f first
#define s second
#define pb push_back
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

int mod=1e9+7;
int add(int a,int b){
    a+=b;
    if(a>=mod)a-=mod;
    return a;
}
int sub(int a,int b){
    a-=b;
    if(a<0)a+=mod;
    return a;
}
int mul(int a,int b){
    return (ll)a*b%mod;
}
const int K=19,L=26;
int n,k;
bool moze[K][L];
vector<int> moraVise(L,0);
vector<int> moraTacno(L,-1);
vector<int> slovaVise;
int nxt[1<<K][L];
int dp[1<<K][K+1];
int calc(int msk,int pos){
    if(dp[msk][pos]!=-1)return dp[msk][pos];
    dp[msk][pos]=0;
    if(pos==k){
        dp[msk][pos]=msk==(1<<sz(slovaVise))-1;
        return dp[msk][pos];
    }
    for(int i=0;i<L;i++){
        if(moze[pos][i]&&nxt[msk][i]!=-1){
            dp[msk][pos]=add(dp[msk][pos],calc(nxt[msk][i],pos+1));
        }
    }
    return dp[msk][pos];
}

int main(){
    memset(dp,-1,sizeof dp);
    scanf("%i %i",&n,&k);
    for(int i=0;i<k;i++)for(int j=0;j<L;j++)moze[i][j]=1;
    for(int i=0;i<n;i++){
        string a,b;
        cin >> a >> b;
        vector<bool> haveX(L);
        vector<int> imaCount(L);
        for(int j=0;j<k;j++){
            int sl=a[j]-'A';
            //printf("%i %i: %i\n",i,j,sl);
            if(b[j]=='O'){
                for(int o=0;o<L;o++){
                    if(o!=sl){
                        moze[j][o]=0;
                    }
                }
                imaCount[sl]++;
            }
            if(b[j]=='-'){
                if(haveX[sl]){
                    printf("0\n");
                    return 0;
                }
                imaCount[sl]++;
                moze[j][sl]=0;
            }
            if(b[j]=='x'){
                haveX[sl]=1;
                moze[j][sl]=0;
            }
        }
        for(int j=0;j<L;j++){
            if(haveX[j]){
                if(moraTacno[j]==-1){
                    moraTacno[j]=imaCount[j];
                }
                if(moraTacno[j]!=imaCount[j]){
                    printf("0\n");
                    return 0;
                }
            }
            else{
                //printf("Mora vise od %i %c\n",imaCount[j],'A'+j);
                moraVise[j]=max(moraVise[j],imaCount[j]);
            }
        }
    }
    /*for(int i=0;i<k;i++){
        for(int j=0;j<L;j++){
            if(moze[i][j]){
                printf("%i moze %c\n",i,j+'A');
            }
        }
    }*/
    for(int i=0;i<L;i++){
        if(moraTacno[i]!=-1&&moraTacno[i]<moraVise[i]){
            printf("0\n");
            return 0;
        }
        if(moraTacno[i]!=-1){
            moraVise[i]=moraTacno[i];
        }
        for(int j=0;j<moraVise[i];j++){
            slovaVise.pb(i);
        }
    }
    for(int msk=0;msk<(1<<sz(slovaVise));msk++){
        int j=0;
        bool laston=true;
        for(int i=0;i<sz(slovaVise);i++){
            bool ok=msk&(1<<i);
            while(j!=slovaVise[i]){
                if(moraTacno[j]!=-1){
                    nxt[msk][j]=-1;
                }
                else{
                    nxt[msk][j]=msk;
                }
                j++;
            }
            if(ok){
                if(i==sz(slovaVise)-1||slovaVise[i+1]!=slovaVise[i]){
                    if(moraTacno[j]!=-1){
                        nxt[msk][j]=-1;
                    }
                    else{
                        nxt[msk][j]=msk;
                    }
                    j++;
                }
                laston=1;
            }
            else{
                if(laston||slovaVise[i-1]!=slovaVise[i]){
                    nxt[msk][j]=msk^(1<<i);
                }
                if(i==sz(slovaVise)-1||slovaVise[i+1]!=slovaVise[i]){
                    j++;
                }
                laston=0;
            }
        }
        while(j<L){
            if(moraTacno[j]!=-1){
                nxt[msk][j]=-1;
            }
            else{
                nxt[msk][j]=msk;
            }
            j++;
        }
    }

    if(sz(slovaVise)>k){
        printf("0\n");
        return 0;
    }
    printf("%i\n",calc(0,0));
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 5
CRANE
xx--x
NASAL
OOxOO

output:

21

result:

ok 1 number(s): "21"

Test #2:

score: 0
Accepted
time: 3ms
memory: 45232kb

input:

1 5
BBBAA
xxxx-

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

2 5
ABCDE
-xxxx
ABCDE
xxxxx

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

1 3
ABC
---

output:

2

result:

ok 1 number(s): "2"

Test #5:

score: 0
Accepted
time: 3ms
memory: 45852kb

input:

1 15
AAAAAAAAAAAAAAB
-xxxxxxxxxxxxxx

output:

918547951

result:

ok 1 number(s): "918547951"

Test #6:

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

input:

1 15
AAAAAAAAAAAAAAA
-xxxxxxxxxxxxxx

output:

0

result:

ok 1 number(s): "0"

Test #7:

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

input:

1 1
K
x

output:

25

result:

ok 1 number(s): "25"

Test #8:

score: 0
Accepted
time: 343ms
memory: 72756kb

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: 559ms
memory: 97976kb

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: 685ms
memory: 98272kb

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: 452ms
memory: 98232kb

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: 452ms
memory: 98256kb

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: 456ms
memory: 97980kb

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: 29ms
memory: 47932kb

input:

26 19
AAAAAAAAAAAAAAAAAAA
-------------------
BBBBBBBBBBBBBBBBBBB
-------------------
CCCCCCCCCCCCCCCCCCC
-------------------
DDDDDDDDDDDDDDDDDDD
-------------------
EEEEEEEEEEEEEEEEEEE
-------------------
FFFFFFFFFFFFFFFFFFF
-------------------
GGGGGGGGGGGGGGGGGGG
-------------------
HHHHHHHHHHHHHH...

output:

0

result:

ok 1 number(s): "0"

Test #15:

score: -100
Time Limit Exceeded

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: