QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#645542#9463. 基础 ABC 练习题Nesraychan0 0ms0kbC++144.3kb2024-10-16 18:54:582024-10-16 18:54:59

Judging History

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

  • [2024-10-16 18:54:59]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-10-16 18:54:58]
  • 提交

answer

#include<bits/stdc++.h>
#define IL inline
#define reg register
#define N 65
#define u32 unsigned
IL int read()
{
	reg int x=0; reg char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	return x; 
}

int testid,testcnt,n,m;
char s1[N],s2[N],s[N*3];
int sa[N],sb[N],ma,mb;
u32 f[N][N][N];

IL bool chk(reg int p,reg char c)
{
	if(s[p]=='?')return 1;
	return s[p]==c;
}

IL void work()
{
	n=read(),m=n*3,ma=mb=0;
	scanf("%s%s%s",s1,s2,s+1);
	for(reg int i=0;i<=n;++i)
	{
		if(s1[i]=='1')sa[++ma]=i;
		if(s2[i]=='1')sb[++mb]=i;
	}
	
	u32 ans=0;
	for(reg int i=1,j,a,b,c;i<=ma;++i)for(j=1;j<=mb;++j)
	{
		std::vector<std::pair<int,int>>limit;
		limit.push_back({sa[i],sb[j]});
		bool ok=1;
		for(auto &[x,y]:limit)ok&=x+y<=n;
		if(!ok)continue;
		memset(f,0,sizeof(f));
		u32 w; f[0][0][0]=1;
		for(a=0;a<=n;++a)for(b=0;b<=n;++b)for(c=0;c<=n;++c)if(w=f[a][b][c])
		{
			if(a<n&&chk(a+b+c+1,'A'))
			{
				bool ok=1;
				for(auto &[x,y]:limit)
				{
					reg int z=n-x-y;
					ok&=c>=a-x+1;
				}
				if(ok)f[a+1][b][c]+=w;
			}
			if(b<n&&chk(a+b+c+1,'B'))
			{
				bool ok=1;
				for(auto &[x,y]:limit)
				{
					reg int z=n-x-y;
					ok&=a>=b-y+1;
				}
				if(ok)f[a][b+1][c]+=w;
			}
			if(c<n&&chk(a+b+c+1,'C'))
			{
				bool ok=1;
				for(auto &[x,y]:limit)
				{
					reg int z=n-x-y;
					ok&=b>=c-z+1;
				}
				if(ok)f[a][b][c+1]+=w;
			}
		}
		ans+=f[n][n][n];
	}
	
	for(reg int i=1,j,a,b,c;i<=ma;++i)for(j=1;j<mb;++j)
	{
		std::vector<std::pair<int,int>>limit;
		limit.push_back({sa[i],sb[j]});
		limit.push_back({sa[i],sb[j+1]});
		bool ok=1;
		for(auto &[x,y]:limit)ok&=x+y<=n;
		if(!ok)continue;
		memset(f,0,sizeof(f));
		u32 w; f[0][0][0]=1;
		for(a=0;a<=n;++a)for(b=0;b<=n;++b)for(c=0;c<=n;++c)if(w=f[a][b][c])
		{
			if(a<n&&chk(a+b+c+1,'A'))
			{
				bool ok=1;
				for(auto &[x,y]:limit)
				{
					reg int z=n-x-y;
					ok&=c>=a-x+1;
				}
				if(ok)f[a+1][b][c]+=w;
			}
			if(b<n&&chk(a+b+c+1,'B'))
			{
				bool ok=1;
				for(auto &[x,y]:limit)
				{
					reg int z=n-x-y;
					ok&=a>=b-y+1;
				}
				if(ok)f[a][b+1][c]+=w;
			}
			if(c<n&&chk(a+b+c+1,'C'))
			{
				bool ok=1;
				for(auto &[x,y]:limit)
				{
					reg int z=n-x-y;
					ok&=b>=c-z+1;
				}
				if(ok)f[a][b][c+1]+=w;
			}
		}
		ans+=f[n][n][n];
	}
	
	for(reg int i=1,j,a,b,c;i<ma;++i)for(j=1;j<=mb;++j)
	{
		std::vector<std::pair<int,int>>limit;
		limit.push_back({sa[i],sb[j]});
		limit.push_back({sa[i+1],sb[j]});
		bool ok=1;
		for(auto &[x,y]:limit)ok&=x+y<=n;
		if(!ok)continue;
		memset(f,0,sizeof(f));
		u32 w; f[0][0][0]=1;
		for(a=0;a<=n;++a)for(b=0;b<=n;++b)for(c=0;c<=n;++c)if(w=f[a][b][c])
		{
			if(a<n&&chk(a+b+c+1,'A'))
			{
				bool ok=1;
				for(auto &[x,y]:limit)
				{
					reg int z=n-x-y;
					ok&=c>=a-x+1;
				}
				if(ok)f[a+1][b][c]+=w;
			}
			if(b<n&&chk(a+b+c+1,'B'))
			{
				bool ok=1;
				for(auto &[x,y]:limit)
				{
					reg int z=n-x-y;
					ok&=a>=b-y+1;
				}
				if(ok)f[a][b+1][c]+=w;
			}
			if(c<n&&chk(a+b+c+1,'C'))
			{
				bool ok=1;
				for(auto &[x,y]:limit)
				{
					reg int z=n-x-y;
					ok&=b>=c-z+1;
				}
				if(ok)f[a][b][c+1]+=w;
			}
		}
		ans+=f[n][n][n];
	}
	
	for(reg int i=1,j,a,b,c;i<ma;++i)for(j=1;j<mb;++j)
	{
		std::vector<std::pair<int,int>>limit;
		limit.push_back({sa[i],sb[j]});
		limit.push_back({sa[i],sb[j+1]});
		limit.push_back({sa[i+1],sb[j]});
		limit.push_back({sa[i+1],sb[j+1]});
		bool ok=1;
		for(auto &[x,y]:limit)ok&=x+y<=n;
		if(!ok)continue;
		memset(f,0,sizeof(f));
		u32 w; f[0][0][0]=1;
		for(a=0;a<=n;++a)for(b=0;b<=n;++b)for(c=0;c<=n;++c)if(w=f[a][b][c])
		{
			if(a<n&&chk(a+b+c+1,'A'))
			{
				bool ok=1;
				for(auto &[x,y]:limit)
				{
					reg int z=n-x-y;
					ok&=c>=a-x+1;
				}
				if(ok)f[a+1][b][c]+=w;
			}
			if(b<n&&chk(a+b+c+1,'B'))
			{
				bool ok=1;
				for(auto &[x,y]:limit)
				{
					reg int z=n-x-y;
					ok&=a>=b-y+1;
				}
				if(ok)f[a][b+1][c]+=w;
			}
			if(c<n&&chk(a+b+c+1,'C'))
			{
				bool ok=1;
				for(auto &[x,y]:limit)
				{
					reg int z=n-x-y;
					ok&=b>=c-z+1;
				}
				if(ok)f[a][b][c+1]+=w;
			}
		}
		ans+=f[n][n][n];
	}
	printf("%u\n",ans);
}

main()
{
	testcnt=read(),testid=read();
	while(testcnt--)work();
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

input:

60 1
1
11
11
ABC
2
111
111
CABABC
3
1111
1111
CAABBCBAC
4
11111
11111
BACBBACBACAC
5
111111
111111
CABCCBBAABCCBAA
6
1111111
1111111
ABABABCACBCBCCACBA
7
11111111
11111111
BCAABACBBCBBABCCAACAC
8
111111111
111111111
CCBCBBBCAABCBCAAAAACBCBA
9
1111111111
1111111111
CCCCACABCBABAABCCAABABBCBBA
10
1111...

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Time Limit Exceeded

Test #22:

score: 0
Time Limit Exceeded

input:

60 3
1
11
11
???
2
111
111
??????
3
1111
1111
?????????
4
11111
11111
????????????
5
111111
111111
???????????????
6
1111111
1111111
??????????????????
7
11111111
11111111
?????????????????????
8
111111111
111111111
????????????????????????
9
1111111111
1111111111
???????????????????????????
10
1111...

output:


result:


Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%