QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#223634#7063. Space Stationveg#TL 6ms4184kbC++14654b2023-10-22 14:31:232023-10-22 14:31:23

Judging History

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

  • [2023-10-22 14:31:23]
  • 评测
  • 测评结果:TL
  • 用时:6ms
  • 内存:4184kb
  • [2023-10-22 14:31:23]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int maxn=1e5+10;
const int mod=1e9+7;

int a[60];
int jc[maxn];
int ans;

void dfs(int rem,int n,int tmp)
{
	if(rem>=50||!n)
	{
		ans=(ans+1ll*tmp*jc[n])%mod;
		return;
	}
	for(int i=1;i<=rem;i++)
		if(a[i])
		{
			a[i]--;
			dfs(rem+i,n-1,1ll*tmp*(a[i]+1)%mod);
			a[i]++;
		}
}

int main()
{
	int n,rem;
	scanf("%d%d",&n,&rem);
	jc[0]=1;
	for(int i=1;i<=n;i++) jc[i]=1ll*jc[i-1]*i%mod;
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		a[x]++;
	}
	dfs(rem,n-a[0],1);
	for(int i=1;i<=a[0];i++) ans=1ll*ans*(n-i+1)%mod;
	printf("%d\n",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2 1 2 3

output:

4

result:

ok single line: '4'

Test #2:

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

input:

5
1 1 1 1 2 3

output:

54

result:

ok single line: '54'

Test #3:

score: 0
Accepted
time: 5ms
memory: 4184kb

input:

100000
47 25 43 22 17 6 15 17 45 4 14 34 46 22 0 8 2 48 41 6 49 42 21 25 48 43 2 17 27 25 38 31 39 48 13 49 24 30 36 19 29 47 48 1 4 5 12 9 21 39 30 21 8 4 9 45 18 0 3 29 26 18 24 39 31 49 22 4 46 21 27 11 11 7 8 3 26 25 29 4 1 21 34 4 44 39 13 26 33 44 5 17 10 32 37 25 44 34 17 14 40 32 27 39 41 6 ...

output:

268605493

result:

ok single line: '268605493'

Test #4:

score: 0
Accepted
time: 6ms
memory: 4176kb

input:

100000
35 39 20 34 18 5 21 21 45 38 48 44 50 42 35 23 21 18 24 9 40 18 16 20 41 27 25 4 0 5 9 7 39 26 47 13 18 27 43 45 31 20 45 39 7 29 4 41 6 39 4 27 7 24 42 10 49 21 9 21 33 12 7 2 24 13 47 11 43 25 8 18 5 14 44 9 14 50 50 19 6 18 45 41 0 27 20 44 17 19 5 26 38 19 1 30 10 32 46 4 24 27 28 32 27 3...

output:

590621358

result:

ok single line: '590621358'

Test #5:

score: -100
Time Limit Exceeded

input:

100000
21 4 24 20 20 30 50 25 47 22 31 30 2 37 43 13 16 12 8 39 31 18 10 42 32 10 49 17 46 35 5 36 13 4 32 4 12 22 49 44 6 18 40 24 34 4 48 22 15 10 1 31 30 44 49 24 29 16 39 11 13 31 42 39 17 28 20 18 15 30 40 23 49 45 3 15 2 24 21 34 11 15 5 2 7 17 27 11 2 44 31 38 16 32 17 9 2 30 49 18 35 46 30 5...

output:


result: