QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#410954#7023. Rainbow GraphzhouhuanyiAC ✓5447ms3708kbC++141.5kb2024-05-14 18:37:492024-05-14 18:37:49

Judging History

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

  • [2024-05-14 18:37:49]
  • 评测
  • 测评结果:AC
  • 用时:5447ms
  • 内存:3708kb
  • [2024-05-14 18:37:49]
  • 提交

answer

#include<iostream>
#include<cstdio>
#define N 64
#define M 4096
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 gcd(int x,int y)
{
	if (!y) return x;
	return gcd(y,x%y);
}
int T,n,mod,ans,inv[N+1],tong[N+1],length,pw[M+1],g[N+1][N+1];
unsigned __int128 dst;
void Adder(int &x,int d)
{
	x+=d;
	if (x>=mod) x-=mod;
	return;
}
int MDS(long long x)
{
	x-=((dst*x)>>62)*mod;
	return x>=mod?x-mod:x;
}
int MD2(int x)
{
	return x<0?x+mod:x;
}
void dfs(int x,int d,int res,bool op,int cnt,int rst)
{
	if (!x)
	{
		Adder(ans,1ll*pw[res+n-length+op]*rst%mod);
		return;
	}
	int dst;
	for (int i=min(x,d);i>=1;--i)
	{
		dst=res;
		for (int j=1;j<=length;++j) dst+=g[tong[j]][i];
		tong[++length]=i,dfs(x-i,i,dst+(i>>1),op|(i&1),(d==i?cnt:0)+1,MDS(1ll*MDS(1ll*rst*inv[i])*inv[(d==i?cnt:0)+1])),--length;
	}
	return;
}
int main()
{
	for (int i=1;i<=N;++i)
		for (int j=1;j<=N;++j)
			g[i][j]=gcd(i,j);
	T=read();
	for (int qt=1;qt<=T;++qt)
	{
		n=read(),mod=read(),dst=(1ull<<62)/mod,ans=0;
		if (n==1)
		{
			printf("Case #%d: 1\n",qt);
			continue;
		}
		inv[1]=pw[0]=1;
		for (int i=2;i<=n;++i) inv[i]=MD2(-1ll*inv[mod%i]*(mod/i)%mod);
		for (int i=1;i<=M;++i) pw[i]=2ll*pw[i-1]%mod;
		dfs(n,n,0,0,0,1);
		for (int i=1;i<=n;++i) ans=1ll*ans*inv[2]%mod;
		printf("Case #%d: %d\n",qt,ans);
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 187ms
memory: 3688kb

input:

5
1 11059
2 729557
3 1461283
4 5299739
63 49121057

output:

Case #1: 1
Case #2: 1
Case #3: 2
Case #4: 3
Case #5: 5694570

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 2413ms
memory: 3676kb

input:

1000
21 1068966139
5 7
11 592605847
5 47
43 1073340277
2 5
10 23
21 1073075699
12 433770173
14 71
10 731029241
20 1061117311
32 1073031341
6 79
5 860731789
4 42979543
13 672313517
34 1073420087
1 31
13 642558071
14 61488023
14 53
32 1073724671
46 1073519287
5 17
5 71
21 1052405707
18 1073364059
12 6...

output:

Case #1: 288610647
Case #2: 0
Case #3: 1182004
Case #4: 7
Case #5: 1024800574
Case #6: 1
Case #7: 0
Case #8: 400305492
Case #9: 87723296
Case #10: 63
Case #11: 33120
Case #12: 25300517
Case #13: 225818772
Case #14: 16
Case #15: 7
Case #16: 3
Case #17: 112236241
Case #18: 477241917
Case #19: 1
Case #...

result:

ok 1000 lines

Test #3:

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

input:

1000
31 1072592011
15 465095539
15 1048107223
47 1073368603
15 500762173
15 901568137
15 855109259
15 854014597
15 545211269
15 925131751
15 195906307
47 1073119147
15 704314207
15 138105463
15 107027447
15 944363789
15 583260739
15 373354823
31 1072014887
15 975386257
15 493331843
15 189869087
15 5...

output:

Case #1: 990292344
Case #2: 328159666
Case #3: 220516164
Case #4: 255553719
Case #5: 332650134
Case #6: 166305029
Case #7: 747088533
Case #8: 745481041
Case #9: 302100610
Case #10: 449459498
Case #11: 120773243
Case #12: 417985009
Case #13: 674253203
Case #14: 32453720
Case #15: 53338318
Case #16: 8...

result:

ok 1000 lines