QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#377126#5066. String-dle CountInfinityNS#TL 0ms45032kbC++173.9kb2024-04-04 22:26:092024-04-04 22:26:10

Judging History

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

  • [2024-04-04 22:26:10]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:45032kb
  • [2024-04-04 22:26:09]
  • 提交

answer

#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 cntImam[L][K+1];
bool neSme[L];
void decode(int msk,int pos){
    for(int i=0;i<L;i++)cntImam[i][pos]=0;
    for(int i=0;i<sz(slovaVise);i++){
        if(msk&(1<<i)){
            cntImam[slovaVise[i]][pos]++;
        }
    }
}
int cc[L];
int encode(int pos){
    for(int i=0;i<L;i++)cc[i]=0;
    int msk=0;
    for(int i=0;i<sz(slovaVise);i++){
        if(cc[slovaVise[i]]!=cntImam[slovaVise[i]][pos]){
            cc[slovaVise[i]]++;
            msk^=1<<i;
        }
    }
    return msk;
}
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;
    decode(msk,pos);
    if(pos==k){
        bool ok=1;
        for(int i=0;i<L;i++){
            if(moraTacno[i]!=-1){
                if(moraTacno[i]!=cntImam[i][pos]){
                    ok=0;
                    break;
                }
            }
            else{
                if(moraVise[i]>cntImam[i][pos]){
                    ok=0;
                    break;
                }
            }
        }
        dp[msk][pos]=ok;
        return dp[msk][pos];
    }
    for(int i=0;i<L;i++){
        if(moze[pos][i]&&!neSme[i]){
            cntImam[i][pos]++;
            dp[msk][pos]=add(dp[msk][pos],calc(encode(pos),pos+1));
            cntImam[i][pos]--;
        }
    }
    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(imaCount[j]==0){
                    neSme[j]=1;
                }
                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);
        }
    }
    if(sz(slovaVise)>k){
        printf("0\n");
        return 0;
    }
    printf("%i\n",calc(0,0));
}

详细

Test #1:

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

input:

2 5
CRANE
xx--x
NASAL
OOxOO

output:

21

result:

ok 1 number(s): "21"

Test #2:

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

input:

1 5
BBBAA
xxxx-

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

2 5
ABCDE
-xxxx
ABCDE
xxxxx

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

1 3
ABC
---

output:

2

result:

ok 1 number(s): "2"

Test #5:

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

input:

1 15
AAAAAAAAAAAAAAB
-xxxxxxxxxxxxxx

output:

918547951

result:

ok 1 number(s): "918547951"

Test #6:

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

input:

1 15
AAAAAAAAAAAAAAA
-xxxxxxxxxxxxxx

output:

0

result:

ok 1 number(s): "0"

Test #7:

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

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...

output:


result: