QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#99927#5820. 置换sichengzhou0 787ms3856kbC++141.2kb2023-04-24 04:11:122023-04-24 04:11:13

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-24 04:11:13]
  • 评测
  • 测评结果:0
  • 用时:787ms
  • 内存:3856kb
  • [2023-04-24 04:11:12]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=3030,M=1e6+6,mod=998244353;
int n,m,p[N],vis[N],cnt[N];
LL f[N],ans,fac[N];
LL ksm(LL x,int y)
{
	LL ret=1;
	while(y)
	{
		if(y&1)
		{
			ret=ret*x%mod;
		}
		x=x*x%mod;
		y>>=1;
	}
	return ret;
}
int gcd(int x,int y)
{
	if(y==0)
	{
		return x;
	}
	return gcd(y,x%y);
}
void work()
{
	ans=1;
	scanf("%d%d",&n,&m);
	fac[0]=1;
	for(int i=1;i<=n;i++)
	{
		fac[i]=fac[i-1]*i%mod;
		vis[i]=cnt[i]=0;
		scanf("%d",&p[i]);
	}
	for(int i=1;i<=n;i++)
	{
		if(vis[i]==0)
		{
			int sz=0;
			vis[i]=1;
			for(int j=p[i];j;j=p[j])
			{
				vis[j]=1;
				sz++;
				if(j==i)
				{
					break;
				}
			}
			cnt[sz]++;
		}
	}
	for(int i=1;i<=n;i++)
	{
		f[0]=1;
		for(int j=1;j<=cnt[i];j++)
		{
			f[j]=0;
		}
	//	cout<<i<<endl;
		for(int j=1;j<=cnt[i];j++)
		{
			for(int k=1;k<=j;k++)
			{
				int len=k*i;
				if(len/gcd(len,m)==i)
				{
				//	cout<<k<<" legal"<<endl;
					f[j]+=f[j-k]*fac[k-1]%mod*ksm(i,k-1)%mod;
					f[j]%=mod;
				}
			}
		//	cout<<j<<' '<<f[j]<<endl;
		}
		ans*=f[cnt[i]];
		ans%=mod;
	}
	printf("%lld\n",ans);
}
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		work();
	}
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3608kb

input:

10
6 5
1 2 6 3 4 5
5 8
1 2 3 4 5
7 5
1 2 3 4 5 6 7
4 4
1 2 3 4
7 7
1 2 3 4 5 6 7
4 4
1 2 3 4
5 4
1 2 4 3 5
8 8
1 2 3 4 5 6 7 8
4 5
1 3 2 4
6 6
1 2 3 4 5 6

output:

1
20
73
11
721
11
0
5230
1
157

result:

wrong answer 2nd lines differ - expected: '56', found: '20'

Test #2:

score: 0
Wrong Answer
time: 1ms
memory: 3640kb

input:

10
4 6
3 1 2 4
5 8
2 1 3 4 5
8 4
1 2 3 4 5 6 7 8
6 5
4 1 2 3 5 6
5 5
1 2 3 4 5
5 5
1 2 3 4 5
6 7
1 2 3 4 5 6
6 4
1 2 3 4 5 6
6 7
6 1 2 3 4 5
7 6
1 2 3 4 5 6 7

output:

0
0
190
1
25
25
1
43
1
313

result:

wrong answer 3rd lines differ - expected: '6224', found: '190'

Test #3:

score: 0
Wrong Answer
time: 0ms
memory: 3576kb

input:

10
6 602552
1 2 3 4 5 6
4 775694
1 2 4 3
6 668467
1 4 2 3 5 6
6 558385
1 2 6 3 4 5
7 832183
4 1 2 3 5 6 7
6 631375
1 2 3 4 5 6
8 519340
1 2 3 5 4 6 7 8
4 636124
1 2 3 4
4 759099
3 1 2 4
7 977752
1 2 3 4 5 6 7

output:

43
0
1
1
1
49
0
11
0
81

result:

wrong answer 1st lines differ - expected: '256', found: '43'

Test #4:

score: 0
Wrong Answer
time: 2ms
memory: 3648kb

input:

10
43 725761
1 2 3 4 5 6 7 8 10 9 11 12 13 15 14 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
37 542860
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 27 26 28 29 30 31 32 33 34 36 35 37
27 793967
2 1 4 3 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...

output:

1
0
1
229758602
0
98755945
424676968
14525735
0
544717359

result:

wrong answer 4th lines differ - expected: '656150888', found: '229758602'

Test #5:

score: 0
Wrong Answer
time: 2ms
memory: 3796kb

input:

10
40 535121
3 1 2 4 5 6 7 8 9 11 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
43 660193
1 2 3 4 5 6 7 8 9 10 11 12 13 14 16 15 19 17 18 20 26 21 22 23 24 25 27 28 29 30 34 31 32 33 35 36 37 38 39 40 41 42 43
38 596459
1 2 4 3 5 6 7 8 9 10 11 12 13 15 14 ...

output:

1
824925040
690690947
99890851
0
0
0
0
0
772159620

result:

wrong answer 2nd lines differ - expected: '544069454', found: '824925040'

Test #6:

score: 0
Wrong Answer
time: 2ms
memory: 3748kb

input:

10
33 892596
1 2 6 3 4 5 9 7 8 10 11 12 14 13 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 32 30 31 33
39 875634
1 2 10 3 4 5 6 7 8 9 11 12 13 14 16 15 17 18 20 19 21 22 23 24 26 25 27 28 29 30 31 32 33 35 34 36 37 38 39
27 856117
1 2 3 4 5 10 6 7 8 9 11 12 13 14 15 16 17 18 20 19 21 24 22 23 25 26 ...

output:

0
0
1
0
10770152
859830352
121985636
902864214
1
414832303

result:

wrong answer 5th lines differ - expected: '860677875', found: '10770152'

Test #7:

score: 0
Wrong Answer
time: 765ms
memory: 3620kb

input:

10
2899 540778
3 1 2 4 5 6 9 7 8 10 11 12 13 14 15 16 17 18 19 20 21 22 24 23 27 25 26 28 29 30 31 32 33 34 35 37 36 38 39 40 41 42 44 43 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 70 68 69 71 72 73 74 75 76 77 78 80 79 81 82 83 89 84 85 86 87 88 90 91 92 93 94 95 96 97 98 ...

output:

0
730169635
0
0
338924507
480987112
0
187787538
0
577455755

result:

wrong answer 2nd lines differ - expected: '786737927', found: '730169635'

Test #8:

score: 0
Wrong Answer
time: 787ms
memory: 3644kb

input:

10
2310 568163
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 26 24 25 27 28 30 29 31 32 33 34 35 36 37 38 39 40 41 46 42 43 44 45 47 48 49 50 51 52 57 53 54 55 56 58 59 61 60 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 ...

output:

1
0
353938774
0
478968956
177056630
0
0
0
686984419

result:

wrong answer 3rd lines differ - expected: '906525565', found: '353938774'

Test #9:

score: 0
Wrong Answer
time: 533ms
memory: 3620kb

input:

10
1564 511376
1 2 3 4 5 6 8 7 9 10 11 12 13 14 15 16 20 17 18 19 21 22 23 24 25 26 28 27 29 30 31 35 32 33 34 36 41 37 38 39 40 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 76 74 75 77 78 82 79 80 81 83 84 85 86 87 88 89 90 91 92 93 94 97 95 96 98 ...

output:

0
479537737
0
0
273335870
0
0
0
0
333925663

result:

wrong answer 2nd lines differ - expected: '207595358', found: '479537737'

Test #10:

score: 0
Wrong Answer
time: 613ms
memory: 3856kb

input:

10
1749 969801
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 34 31 32 33 36 35 37 38 39 40 41 42 43 44 45 46 48 47 49 50 51 54 52 53 55 56 57 58 60 59 61 62 63 64 65 66 67 68 69 70 71 72 73 75 74 76 77 78 79 80 81 82 83 84 85 86 89 87 88 90 91 92 93 94 95 96 97 99 ...

output:

0
0
1
866736885
250762188
0
0
0
0
444942876

result:

wrong answer 4th lines differ - expected: '705667952', found: '866736885'