QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#287265#5066. String-dle CountzhouhuanyiTL 248ms5956kbC++203.0kb2023-12-20 08:59:292023-12-20 08:59:29

Judging History

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

  • [2023-12-20 08:59:29]
  • 评测
  • 测评结果:TL
  • 用时:248ms
  • 内存:5956kb
  • [2023-12-20 08:59:29]
  • 提交

answer

#include<iostream>
#include<cstdio>
#define N 494
#define M 19
#define K 26
#define mod 1000000007
using namespace std;
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
int fast_pow(int a,int b)
{
	int res=1,mul=a;
	while (b)
	{
		if (b&1) res=1ll*res*mul%mod;
		mul=1ll*mul*mul%mod,b>>=1;
	}
	return res;
}
void Adder(int &x,int d)
{
	x+=d;
	if (x>=mod) x-=mod;
	return;
}
void Adder2(int &x,int d)
{
	x+=d;
	if (x<0) x+=mod;
	return;
}
int MD(int x)
{
	return x>=mod?x-mod:x;
}
int MD2(int x)
{
	return x<0?x+mod:x;
}
int n,k,S[1<<M],st[K+1],delta[K+1],cnt[K+1],l[K+1],r[K+1],tr[K+1],F[1<<M][M+1],dp[K+1][M+1],C[N+1][M+1],ans;
char a[M+1],b[M+1];
bool used[K+1];
int main()
{
	int sl,sr,rcnt,dst;
	bool op;
	for (int i=0;i<=N;++i) C[i][0]=1;
	for (int i=1;i<=N;++i)
		for (int j=1;j<=min(i,M);++j)
			C[i][j]=MD(C[i-1][j-1]+C[i-1][j]);
	n=read(),k=read();
	for (int i=1;i<=k;++i) S[i]=(1<<26)-1;
	for (int i=0;i<26;++i) l[i]=0,r[i]=k;
	for (int i=1;i<=n;++i)
	{
		for (int j=1;j<=k;++j) cin>>a[j];
		for (int j=1;j<=k;++j) cin>>b[j];
		for (int j=0;j<26;++j) cnt[j]=used[j]=0;
		for (int j=1;j<=k;++j)
		{
			if (b[j]=='O') S[j]&=(1<<(a[j]-'A')),cnt[a[j]-'A']++;
			else
			{
				S[j]&=(((1<<26)-1)^(1<<(a[j]-'A')));
				if (b[j]=='-')
				{
					if (used[a[j]-'A'])
					{
						puts("0");
						return 0;
					}
					cnt[a[j]-'A']++;
				}
				else used[a[j]-'A']=1;
			}
		}
		for (int j=0;j<26;++j)
			if (cnt[j]||used[j])
			{
				if (used[j]) l[j]=max(l[j],cnt[j]),r[j]=min(r[j],cnt[j]);
				else l[j]=max(l[j],cnt[j]);
			}
	}
	for (int i=1;i<=k;++i)
		if (!S[i])
		{
			puts("0");
			return 0;
		}
	for (int i=1;i<=k;++i)
		for (int j=0;j<26;++j)
			if ((S[i]>>j)&1)
				st[j]|=(1<<(i-1));
	for (int i=0;i<26;++i)
	{
		r[i]=min(r[i],__builtin_popcount(st[i]));
		if (l[i]>r[i])
		{
			puts("0");
			return 0;
		}
	}
	for (int i=0;i<(1<<k);++i)
	{
		dst=rcnt=0;
		for (int j=0;j<=26;++j)
			for (int t=0;t<=k;++t)
				dp[j][t]=F[j][t]=0;
		dp[0][0]=op=1,sl=sr=0;
		for (int j=0;j<26;++j)
		{
			delta[j]=__builtin_popcount(i&st[j]),tr[j]=min(r[j],delta[j]),dst+=tr[j];
			if (l[j]>tr[j])
			{
				op=0;
				break;
			}
			for (int t=l[j];t<=tr[j];++t) F[j][t]=C[delta[j]][t];
		}
		if (dst<k||!op) continue;
		for (int j=0;j<26;++j)
		{
			if (l[j]==0&&tr[j]==delta[j])
			{
				rcnt+=delta[j];
				for (int k=sl;k<=sr;++k) dp[j+1][k]=dp[j][k];
			}
			else
			{
				for (int s=sl;s<=sr;++s)
					for (int t=l[j];t<=min(k-s,tr[j]);++t)
						Adder(dp[j+1][s+t],1ll*dp[j][s]*F[j][t]%mod);
				sl+=l[j],sr=min(sr+tr[j],k);
			}
		}
		if (!(__builtin_popcount(((1<<k)-1)^i)&1))
		{
			for (int j=0;j<=k;++j) Adder(ans,1ll*dp[26][j]*C[rcnt][k-j]%mod);
		}
		else
		{
			for (int j=0;j<=k;++j) Adder2(ans,-1ll*dp[26][j]*C[rcnt][k-j]%mod);
		}
	}
	printf("%d\n",ans);
	return 0;
}

详细

Test #1:

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

input:

2 5
CRANE
xx--x
NASAL
OOxOO

output:

21

result:

ok 1 number(s): "21"

Test #2:

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

input:

1 5
BBBAA
xxxx-

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

2 5
ABCDE
-xxxx
ABCDE
xxxxx

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

1 3
ABC
---

output:

2

result:

ok 1 number(s): "2"

Test #5:

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

input:

1 15
AAAAAAAAAAAAAAB
-xxxxxxxxxxxxxx

output:

918547951

result:

ok 1 number(s): "918547951"

Test #6:

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

input:

1 15
AAAAAAAAAAAAAAA
-xxxxxxxxxxxxxx

output:

0

result:

ok 1 number(s): "0"

Test #7:

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

input:

1 1
K
x

output:

25

result:

ok 1 number(s): "25"

Test #8:

score: 0
Accepted
time: 209ms
memory: 5916kb

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: 220ms
memory: 5916kb

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: 248ms
memory: 5848kb

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

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: 208ms
memory: 5852kb

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: 202ms
memory: 5928kb

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

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: