QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#789470#5066. String-dle Countlouhao088WA 230ms26080kbC++232.8kb2024-11-27 20:28:092024-11-27 20:28:10

Judging History

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

  • [2024-11-27 20:28:10]
  • 评测
  • 测评结果:WA
  • 用时:230ms
  • 内存:26080kb
  • [2024-11-27 20:28:09]
  • 提交

answer

#pragma GCC Optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+5,mod=1e9+7;
#define pb push_back
inline int read(){
    char ch=getchar();int x=0;bool f=0;
    for(;!isdigit(ch);ch=getchar())if(ch=='-'){f=1;}
    for(;isdigit(ch);ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
    if(f==1)x=-x;
    return x;
}
int n,m,k,T;
int least[maxn],cnt[maxn];
int g[maxn][37];
char s1[maxn],b[maxn];
int c[maxn],a[maxn];
typedef unsigned long long ull;
const ull Base=2333;
unordered_map<ull,int>f[27];
ull pw[27];
int dfs(int x,vector<int> &tmp,ull hash,int u){
	if(x==m+1&&!u)return 1;
	if(x==m+1&&u)return 0;
	if(x+u>m+1)return 0;
	if(f[x].find(hash)!=f[x].end()){return f[x][hash];}
	int sum=0;
	//cout<<x<<" "<<tmp.size()<<" "<<u<<endl;
	if(c[x]){
		if(tmp[c[x]]){
			tmp[c[x]]--;
			hash-=pw[c[x]];
			sum=(sum+dfs(x+1,tmp,hash,u-1))%mod;
			tmp[c[x]]++;
			hash+=pw[c[x]];
		}
		else if(cnt[c[x]]==-1){
			sum=(sum+dfs(x+1,tmp,hash,u))%mod;
		}
	}
	else{
		for(int i=0;i<26;i++){
			if(!g[x][i]){
				if(tmp[i]){
					tmp[i]--;
					hash-=pw[i];
					sum=(sum+dfs(x+1,tmp,hash,u-1))%mod;
					tmp[i]++;
					hash+=pw[i];
				}
				else if(cnt[i]==-1){
					//cout<<i<<endl;
					sum=(sum+dfs(x+1,tmp,hash,u))%mod;
				}
			}
		}
	}
	sum%=mod;
	f[x][hash]=sum;
	return sum;
}
signed main(){
	pw[0]=1; for(int i=1;i<=26;i++) pw[i]=pw[i-1]*Base;
    n=read(),m=read();
	for(int i=0;i<26;i++)cnt[i]=-1;
	for(int i=1;i<=n;i++){
		scanf("%s",s1+1);
		scanf("%s",b+1);
		vector<int>tmp,flag;
		tmp.resize(29);flag.resize(29);
		for(int j=1;j<=m;j++)a[j]=s1[j]-'A';
		for(int j=1;j<=m;j++)
		if(b[j]=='O'){
				if(flag[a[j]]){puts("0");return 0;}
				if(g[j][a[j]]){
					puts("0");return 0;
				}
				tmp[a[j]]++;
				if(!c[j]){
					c[j]=a[j];
				}
				else if(c[j]!=a[j]){
					puts("0");return 0;
				}
			}
		for(int j=1;j<=m;j++){
			//cout<<i<<" "<<j<<endl;
			
			if(b[j]=='-'){
				if(c[j]&&c[j]==a[j]){puts("0");return 0;}
				if(flag[a[j]]){puts("0");return 0;}
				//cout<<j<<" "<<a[j]<<endl;
				g[j][a[j]]=1;tmp[a[j]]++;

			}
			if(b[j]=='x'){
				if(c[j]&&c[j]==a[j]){puts("0");return 0;}
				flag[a[j]]=1;
				g[j][a[j]]=1;
				if(least[a[j]]>tmp[a[j]]){
						puts("0");return 0;
					}
				if(cnt[a[j]]>=0){
					if(cnt[a[j]]!=tmp[a[j]]){
						puts("0");return 0;
					}
				}
				else{
					cnt[a[j]]=tmp[a[j]];
					least[a[j]]=tmp[a[j]];
				}
			}
			
		}
		for(int j=0;j<26;j++){
			if(tmp[j]>cnt[j]&&cnt[j]>=0){
				puts("0");return 0;
			}
			least[j]=max(least[j],tmp[j]);
		}
	}
	vector<int>tmp;tmp.clear();tmp.resize(26);
	int s=0;
	ull hash=0;
	for(int i=0;i<26;i++){
		tmp[i]=least[i];s+=least[i];
		hash+=tmp[i]*pw[i];
	}
	cout<<dfs(1,tmp,hash,s)<<endl;
}

詳細信息

Test #1:

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

input:

2 5
CRANE
xx--x
NASAL
OOxOO

output:

21

result:

ok 1 number(s): "21"

Test #2:

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

input:

1 5
BBBAA
xxxx-

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

2 5
ABCDE
-xxxx
ABCDE
xxxxx

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

1 3
ABC
---

output:

2

result:

ok 1 number(s): "2"

Test #5:

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

input:

1 15
AAAAAAAAAAAAAAB
-xxxxxxxxxxxxxx

output:

918547951

result:

ok 1 number(s): "918547951"

Test #6:

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

input:

1 15
AAAAAAAAAAAAAAA
-xxxxxxxxxxxxxx

output:

0

result:

ok 1 number(s): "0"

Test #7:

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

input:

1 1
K
x

output:

25

result:

ok 1 number(s): "25"

Test #8:

score: 0
Accepted
time: 216ms
memory: 25928kb

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: 206ms
memory: 25856kb

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: 209ms
memory: 25948kb

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: 175ms
memory: 25984kb

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: 170ms
memory: 25180kb

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: 184ms
memory: 25944kb

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

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: 230ms
memory: 26080kb

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

input:

1 3
PYP
xxx

output:

13824

result:

ok 1 number(s): "13824"

Test #17:

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

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

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

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

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

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

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

input:

1 5
VYQWB
x-xxx

output:

835275

result:

ok 1 number(s): "835275"

Test #24:

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

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

input:

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

output:

2783

result:

ok 1 number(s): "2783"

Test #26:

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

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:

1

result:

ok 1 number(s): "1"

Test #27:

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

input:

15 5
GZULJ
xxx-x
AXDPU
xxx-x
BWJIU
xxxxx
NKIND
xxxxx
YXMQF
xxxxx
RGAUS
xxxxx
VXZEJ
xxx-x
ITBNY
x-xxx
HJXRL
xxxx-
IHDML
xxxx-
GHHPP
xxxxO
PFZNR
-xxxx
MOMTI
x-x-x
UNJHO
xxxx-
EPIPE
O-xxx

output:

1

result:

ok 1 number(s): "1"

Test #28:

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

input:

20 5
WSHYB
-xx-x
CAVYO
Oxx-x
ADNZR
xxxxx
DRNVU
xxxx-
YEHWB
-xx-x
MVHPW
xxxx-
NJALD
xxx-x
SGNTS
xxxxx
DKHHP
xxxxx
GYDKZ
x-xxx
KSRVD
xxxxx
DYGKH
x-xxx
DNSME
xxxxx
DDUUJ
xxxOx
EPQGV
xxxxx
TFXTG
xxxxx
SGXNC
xxxx-
JOVUX
xxxOx
EHBYU
xxx--
LCZYD
--x-x

output:

3

result:

ok 1 number(s): "3"

Test #29:

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

input:

10000 5
UERNA
xxxx-
KIWJZ
xxxxx
LPMLP
xxxxx
WVPCT
x-xx-
SLFMH
xxxxx
HTZGM
xOxxx
GFTSP
xx-xx
PRBTN
xxx-x
XCOWY
xxxxx
EAHPE
x-xxx
XWFLX
xxxxx
ZHSVX
xxx-x
YQHKK
x-xxx
QWKNH
-xxxx
LBKBU
xxxxx
TCMXG
-xxxx
PQUMQ
x-xxx
JFWSJ
xxxxx
JSQFA
xx-x-
OXKVR
xxx-x
OWMXL
xxxxx
WJETS
xxx-x
BPNFO
xxxxx
BFLCW
xxxxx
EWAQ...

output:

1

result:

ok 1 number(s): "1"

Test #30:

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

input:

1 10
UZWZMLRBON
-xxxx-x--x

output:

108066093

result:

ok 1 number(s): "108066093"

Test #31:

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

input:

3 10
CYGFEKBVZY
xxx-xxxxxx
KNRFGBVTVK
x-x-xxx-xx
RRSEPXGYLJ
xxxx--xxxx

output:

322428370

result:

ok 1 number(s): "322428370"

Test #32:

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

input:

5 10
VSVMKIMLTX
OxxxOxxx-x
QKDDMDRUCB
x-xxxx-xxx
UNQAFDUZQX
xxxxxxx-xx
VUUSNBQTFE
Oxxxxxx-x-
NKAXCIVSFD
x-xxxx-xxx

output:

7078784

result:

ok 1 number(s): "7078784"

Test #33:

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

input:

10 10
ZNASODMTHF
xxxx-xxO-x
AGKLZJSLIC
xx-xxxxx-x
WJVQUIBCPS
-xx-x--xxx
KHVLHJGWLM
-xxxOxx-xx
UOJUVRJXKT
xOxxxxx---
GXTGEQBJPZ
x--xx--xxx
YQZQWBCTYH
x-xx-OxOx-
FCPCTHSSUK
xxxx--xxx-
WUQKPNYQWL
xx--xxxxOx
JREXWEWTJA
xxxO-xxOxx

output:

15

result:

ok 1 number(s): "15"

Test #34:

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

input:

15 10
BSRHUHFKDB
xx---xxxxx
IYWQJKDFBK
xxxx-xxxxx
EEDAEFQMMQ
xxx-xxx-xx
OQBUXEEWXL
xxx--xxxxx
BHPKFDWCPR
x--xxxx-x-
WRWYCQTWDF
x-xx-xxxxx
FBOTDYYMGO
xxxxxxx--x
SGLWOYFWZY
x-xxxxxxxx
BKXJGXUTDI
xxxO-O-xxx
WKFDXQRCEZ
xxxx-x--xx
WZQYEIXVGV
xxxxxx-x-x
VYFIAADRIB
xxxx-xx-xx
CLZGWKNRIH
-xx-xxx-x-
HGRDECGM...

output:

833

result:

ok 1 number(s): "833"

Test #35:

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

input:

20 10
FCCKSZOJLC
xxx---xx-x
GGEDVVPNOV
xxOxxxxxxx
SGGDAIAHIP
-xxx-xxxxx
GGVAULXPGP
xxx--Oxxxx
DLLQSWLEVI
x-x--xO-xx
DUWRFTNQQA
x-xxxxx-x-
MHTFMAYJDN
xxxxx-xxxx
FUYVYGXIUL
x-xxxxxx--
NJSBZWRJKT
xx-x-xxxOx
DMSYQXGEXZ
xx-xOxx-xO
OEUFRLYPSE
x--xxOxx-x
BFNSAKQXSL
xxx----xx-
XWKTQTTAVG
xx-xOxxOxx
TUQXRAMR...

output:

2

result:

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