QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#276736#4182. Bill 的挑战SoyTony100 ✓36ms17340kbC++141.9kb2023-12-06 10:12:452023-12-06 10:12:46

Judging History

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

  • [2023-12-06 10:12:46]
  • 评测
  • 测评结果:100
  • 用时:36ms
  • 内存:17340kb
  • [2023-12-06 10:12:45]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
const int maxn=1e5+10;
const int maxm=5e4+10;
const int mod=1000003;
const ull base1=233;
const ull base2=19260817;
const int maxxn=0x7fffffff;
const int minxn=-0x7fffffff;
const db inf=1e13;
const db eps=1e-8;
inline ll read(){
    int x=0,w=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
    while(c<='9'&&c>='0'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return x*w;
}
int t,n,k;
char s[105][105];
int sit[105][30];
int dp[105][1<<15];
int ans=0;
int main(){
    t=read();
    while(t--){
        ans=0;
        n=read(),k=read();
        memset(sit,0,sizeof(sit));
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=n;i++){
            scanf("%s",s[i]);
        }
        int len=strlen(s[1]);
        for(int i=0;i<len;i++){
            for(char c='a';c<='z';c++){
                for(int j=1;j<=n;j++){
                    if(s[j][i]==c||s[j][i]=='?'){
                        sit[i][c-'a']|=(1<<(j-1));
                    }
                }
            }
        }
        dp[0][(1<<n)-1]=1;
        for(int i=0;i<len;i++){
            for(int j=0;j<(1<<n);j++){
                if(dp[i][j]){
                    for(char c='a';c<='z';c++){
                        dp[i+1][sit[i][c-'a']&j]=(dp[i+1][sit[i][c-'a']&j]+dp[i][j])%mod;
                    }
                }
            }
        }
        for(int i=0;i<(1<<n);i++){
            int cnt=0;
            for(int j=1;j<(1<<n);j<<=1){
                cnt+=((i&j))?1:0;
            }
            if(cnt==k){
                ans=(ans+dp[len][i])%mod;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

详细

Test #1:

score: 10
Accepted
time: 0ms
memory: 17312kb

input:

5
3 3
???r???
???????
???????
3 4
???????
?????a?
???????
3 3
???????
?a??j??
????aa?
3 2
a??????
???????
???????
3 2
???????
???a???
????a??

output:

914852
0
0
871234
67018

result:

ok 5 lines

Test #2:

score: 10
Accepted
time: 0ms
memory: 17248kb

input:

5
4 5
????aa????
?q????????
??????????
??????????
4 4
a?????????
??????????
????????a?
??????????
4 2
??????????
?????????a
??????????
??????????
4 2
??????????
??????????
??????????
??????????
4 2
??????????
??????????
??????????
??o???????

output:

0
438098
0
0
0

result:

ok 5 lines

Test #3:

score: 10
Accepted
time: 0ms
memory: 17244kb

input:

5
5 2
?????????????a??????
???????????a???????a
????????????????????
????????????????????
??????????????z?????
5 1
??o??a????????v?????
??????????????a?????
????a???????????????
????a?a?????????????
???????????????x????
5 1
???????????????????a
?????at????a?????a??
????ap?????x????????
??aa?????????...

output:

190202
401251
455264
0
75551

result:

ok 5 lines

Test #4:

score: 10
Accepted
time: 3ms
memory: 17312kb

input:

5
10 4
????????????a???????
h???????????????????
??????????a?????a???
????a?????????????a?
??????a??h??????????
????????????????????
?????a??????????????
??????a?????????a??a
???????e????????????
???u?????????????a??
10 4
??a???k?????????????
??????????a?????????
????????i???????????
?????????????a?...

output:

723429
302624
564048
487189
801874

result:

ok 5 lines

Test #5:

score: 10
Accepted
time: 6ms
memory: 17328kb

input:

5
10 8
????????a??????????a?a??????a?
?a?????a???aa???a?????????????
??????????????????????????????
????????s?????????????????????
??????????????????????????????
????????aaa??????a?????q??????
?????????????????????????a????
?ra?a?????????????????????a???
??????????????????????????????
???????????g?t...

output:

356994
654442
796058
989628
4675

result:

ok 5 lines

Test #6:

score: 10
Accepted
time: 4ms
memory: 17244kb

input:

5
13 6
?????????????????????????u????
?????????????ha???????????????
??????????????????????????????
????a????????????????a???????a
?a??????????????????????e?????
????????a????a????????????????
????????q??a??????????????????
??a?????????a?????a???????????
???a?????a????a??????a????????
???????a??????...

output:

65451
721717
925995
431782
373388

result:

ok 5 lines

Test #7:

score: 10
Accepted
time: 9ms
memory: 17248kb

input:

5
13 5
????????a??a???????????a??????
?????????????????a?????a??????
??????????????????????????????
?????????????????????????a????
????????????????????a?????????
??????????????p?????????????a?
a?????????????a???????????????
???????h???????a???a??????????
???????b??????a???????????????
??????????????...

output:

484709
109322
30417
606388
467770

result:

ok 5 lines

Test #8:

score: 10
Accepted
time: 36ms
memory: 17340kb

input:

5
15 8
???????a??a??a?????????????????????b??????????????
????????????????????????????a?????????????????h???
?????a???????????????????????a??n????????????????a
????????????????????????a?????????a??????q????????
?a?????????????????????a??????aa??????????????????
??a????????????????????????a??????????...

output:

421412
49423
565175
443972
215715

result:

ok 5 lines

Test #9:

score: 10
Accepted
time: 32ms
memory: 17316kb

input:

5
15 7
?????v?????????a????a??????????????????a??????????
???????????????????a???aa?????????????????????????
????????????????????????????????????????a?????????
???????????????????a??????????????????????????????
????a????????????z?????????????y???????????????k??
???????g????????????a????????????????a...

output:

699540
970873
662432
142995
0

result:

ok 5 lines

Test #10:

score: 10
Accepted
time: 35ms
memory: 17332kb

input:

5
15 8
??????????????????a???????????????????????????????
????????a???????ac????????????a??????r????f???n???
???a????????????????????????????????a?????????????
???????????????????????????a??????e???????????????
a????????????????????a????????????????????????a???
?????v??a??????????a???????a??????????...

output:

668524
169327
8346
503538
228330

result:

ok 5 lines