QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#333938#5066. String-dle CountC1942huangjiaxuWA 92ms8036kbC++141.6kb2024-02-20 20:29:342024-02-20 20:29:34

Judging History

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

  • [2024-02-20 20:29:34]
  • 评测
  • 测评结果:WA
  • 用时:92ms
  • 内存:8036kb
  • [2024-02-20 20:29:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int P=1e9+7;
int n,m,ct[26],ac[26],c[26],f[1<<19],pc[1<<19];
bool ban[19][26],bn[26],lim[26];
char s[19],t[19];
vector<int>va;
inline void Add(int &x,int y){
	if((x+=y)>=P)x-=P;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<26;++i)ct[i]=0;
	for(int i=0;i<m;++i)ac[i]=-1;
	for(int i=1;i<=n;++i){
		scanf("%s%s",s,t);
		memset(c,0,sizeof(c));
		memset(bn,false,sizeof(bn));
		for(int j=0;j<m;++j){
			int u=s[j]-'A';
			if(t[j]=='O'){
				if(~ac[j]&&ac[j]!=u)return puts("0"),0;
				ac[j]=u,++c[u];
				continue;
			}
			ban[j][u]=true;
			if(t[j]=='-'){
				if(bn[u])return puts("0"),0;
				++c[u];
			}else bn[u]=true;
		}
		for(int j=0;j<26;++j){
			if(bn[j]&&(c[j]<ct[j]||lim[j]&&c[j]!=ct[j]))return puts("0"),0;
			if(bn[j])lim[j]=true,ct[j]=c[j];
			else ct[j]=max(ct[j],c[j]);
		}
	}
	for(int i=0;i<26;++i)if(~ac[i]&&ban[i][ac[i]])return puts("0"),0;
	for(int i=0;i<26;++i)for(int j=1;j<=ct[i];++j)va.push_back(i);
	if(va.size()>m)return puts("0"),0;
	while(va.size()<m)va.push_back(26);
	for(int i=1;i<1<<m;++i)pc[i]=pc[i>>1]+(i&1);
	f[0]=1;
	for(int S=0;S<(1<<m)-1;++S)if(f[S]){
		int u=pc[S];
		memset(c,0,sizeof(c));
		for(int i=0;i<m;++i)if(va[i]!=26&&!(S>>i&1))++c[va[i]];
		for(int i=u+1;i<m;++i)if(~ac[i])--c[ac[i]];
		for(int i=0;i<m;++i)if(!(S>>i&1)){
			if(i&&va[i]==va[i-1]&&!(S>>i-1&1))continue;
			if(va[i]==26){
				if(ac[u]!=-1)continue;
				for(int j=0;j<26;++j)if(!lim[j]&&!c[j]&&!ban[u][j])Add(f[S|1<<i],f[S]);
			}else if(!ban[u][va[i]]&&(ac[u]==-1||ac[u]==va[i]))Add(f[S|1<<i],f[S]);
		}
	}
	printf("%d\n",f[(1<<m)-1]);
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3796kb

input:

2 5
CRANE
xx--x
NASAL
OOxOO

output:

21

result:

ok 1 number(s): "21"

Test #2:

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

input:

1 5
BBBAA
xxxx-

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

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

input:

1 15
AAAAAAAAAAAAAAB
-xxxxxxxxxxxxxx

output:

918547951

result:

ok 1 number(s): "918547951"

Test #6:

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

input:

1 15
AAAAAAAAAAAAAAA
-xxxxxxxxxxxxxx

output:

0

result:

ok 1 number(s): "0"

Test #7:

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

input:

1 1
K
x

output:

25

result:

ok 1 number(s): "25"

Test #8:

score: 0
Accepted
time: 88ms
memory: 8036kb

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: 84ms
memory: 7972kb

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: 83ms
memory: 7844kb

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: 78ms
memory: 7876kb

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: 83ms
memory: 8032kb

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: 92ms
memory: 7816kb

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

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: 73ms
memory: 7848kb

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

input:

1 3
PYP
xxx

output:

13824

result:

ok 1 number(s): "13824"

Test #17:

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

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

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

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: 0
Accepted
time: 1ms
memory: 3884kb

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:

1

result:

ok 1 number(s): "1"

Test #21:

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

input:

20 3
FPR
xxx
FHF
xxx
WBH
xxx
XGA
xx-
QAC
x-x
JYS
xxx
ARR
Oxx
AAF
Oxx
LDY
xxx
ESD
xxx
QMB
xxx
EMS
xxx
UFT
xx-
JCK
xxO
YBH
xxx
KEN
-xx
FVL
xxx
PJP
xxx
DRB
xxx
UDL
xxx

output:

1

result:

ok 1 number(s): "1"

Test #22:

score: 0
Accepted
time: 2ms
memory: 3880kb

input:

10000 3
XIX
xxx
RRY
xxx
RJB
xxx
XUT
x-x
BQB
xxx
RDP
xxx
EEX
xxx
DYJ
xxx
NHI
-xx
VMD
xxx
IVU
xxO
VBR
xxx
CJE
Oxx
BCF
x-x
WSS
xxx
ARP
xxx
HYR
xxx
YTO
xxx
NLJ
-xx
NMU
-xO
GUY
x-x
KAC
xx-
UYQ
-xx
OBU
xxO
ANA
xOx
HCK
x-x
GOX
xxx
ZNU
xOO
LSH
xxx
COM
Oxx
OAM
xxx
HNF
xOx
VOX
xxx
CZM
Oxx
KXM
xxx
MAN
xx-
RUG
...

output:

1

result:

ok 1 number(s): "1"

Test #23:

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

input:

1 5
VYQWB
x-xxx

output:

835275

result:

ok 1 number(s): "835275"

Test #24:

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

input:

3 5
UFJVJ
xxxxx
XAHKG
x-Oxx
ITJDN
--xxx

output:

150

result:

ok 1 number(s): "150"

Test #25:

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

input:

5 5
QJUFA
-xOxx
BDVNF
xxxxx
TABZV
xxxxx
KSFCQ
xxxx-
PFZOQ
xxxx-

output:

2783

result:

ok 1 number(s): "2783"

Test #26:

score: -100
Wrong Answer
time: 0ms
memory: 3792kb

input:

10 5
DOBUN
xxxxx
POMVH
xxOxx
PNCJB
xxxxx
GCWID
xxx-x
XPPHR
xxxxx
ZMXCW
xOxxx
CBSKY
xxxxO
GTHGA
xxxx-
IIHSL
Oxxxx
TBRSZ
xxxxx

output:

0

result:

wrong answer 1st numbers differ - expected: '1', found: '0'