Submission #1837934


Source Code Expand

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define regsiter register
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
}
int d[333];
const int M=1000000007;
int f[2][333][666];
int fac[333];
int invf[333];
int ex(int b,int e)
{
	int ans=1;
	for(;e;e>>=1,b=(long long)b*b%M)
		if(e&1)ans=(long long)ans*b%M;
	return ans;
}
int main()
{
	int n=io::F();
	for(register int i=1;i<=n;++i)d[i]=io::F();
	fac[0]=1;
	for(register int i=1;i<=n;++i)fac[i]=(long long)fac[i-1]*i%M;
	int fl=1;
	for(register int i=1;i<=n;++i)if(d[i]!=2)fl=0;
	if(fl)
	{
		printf("%lld\n",fac[n-1]*(long long)(M+1>>1)%M);
		return 0;
	}
	invf[n]=ex(fac[n],M-2);
	for(register int i=n-1;i>=0;--i)invf[i]=(i+1)*(long long)invf[i+1]%M;
	int(*x)[666]=f[0],(*y)[666]=f[1];
	f[0][0][0]=1;
	for(register int i=1;i<=n;++i,std::swap(x,y))
	{
		for(register int j=0;j<=i;++j)
			for(register int k=0;k<=n+n;++k)
			{
				y[j][k]=x[j][k]*(long long)invf[d[i]-1]%M;
				if(d[i]>=2&&j>=1&&k+2>=d[i])y[j][k]=(y[j][k]+x[j-1][k-d[i]+2]*(long long)invf[d[i]-2])%M;				
			}
	}
	#define register
	int ans=0;
	for(register int i=3;i<n;++i)
		for(register int j=1;j<=n+n;++j)
			ans=(ans+(long long)x[i][j]*fac[n-i-1]%M*fac[i-1]%M*invf[j-1]%M*invf[2]%M*fac[j]%M)%M;
	printf("%d\n",ans);
	return 0;
}


Submission Info

Submission Time
Task F - Unicyclic Graph Counting
User ESpace
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 1937 Byte
Status AC
Exec Time 93 ms
Memory 1792 KB

Judge Result

Set Name Sample Subtask1 Subtask2 Subtask3 All
Score / Max Score 0 / 0 200 / 200 200 / 200 300 / 300 300 / 300
Status
AC × 2
AC × 9
AC × 18
AC × 28
AC × 39
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt
Subtask1 00_example_01.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s1_08.txt
Subtask2 00_example_01.txt, 00_example_02.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s1_08.txt, s2_09.txt, s2_10.txt, s2_11.txt, s2_12.txt, s2_13.txt, s2_14.txt, s2_15.txt, s2_16.txt
Subtask3 00_example_01.txt, 00_example_02.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s1_08.txt, s2_09.txt, s2_10.txt, s2_11.txt, s2_12.txt, s2_13.txt, s2_14.txt, s2_15.txt, s2_16.txt, s3_17.txt, s3_18.txt, s3_19.txt, s3_20.txt, s3_21.txt, s3_22.txt, s3_23.txt, s3_24.txt, s3_25.txt, s3_26.txt
All 00_example_01.txt, 00_example_02.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s1_08.txt, s2_09.txt, s2_10.txt, s2_11.txt, s2_12.txt, s2_13.txt, s2_14.txt, s2_15.txt, s2_16.txt, s3_17.txt, s3_18.txt, s3_19.txt, s3_20.txt, s3_21.txt, s3_22.txt, s3_23.txt, s3_24.txt, s3_25.txt, s3_26.txt, s4_27.txt, s4_28.txt, s4_29.txt, s4_30.txt, s4_31.txt, s4_32.txt, s4_33.txt, s4_34.txt, s4_35.txt, s4_36.txt, s4_37.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 1 ms 256 KB
00_example_02.txt AC 1 ms 256 KB
s1_01.txt AC 1 ms 128 KB
s1_02.txt AC 1 ms 128 KB
s1_03.txt AC 1 ms 128 KB
s1_04.txt AC 1 ms 128 KB
s1_05.txt AC 1 ms 128 KB
s1_06.txt AC 1 ms 128 KB
s1_07.txt AC 1 ms 128 KB
s1_08.txt AC 1 ms 128 KB
s2_09.txt AC 1 ms 256 KB
s2_10.txt AC 1 ms 256 KB
s2_11.txt AC 1 ms 256 KB
s2_12.txt AC 1 ms 256 KB
s2_13.txt AC 1 ms 256 KB
s2_14.txt AC 1 ms 128 KB
s2_15.txt AC 1 ms 256 KB
s2_16.txt AC 1 ms 256 KB
s3_17.txt AC 1 ms 384 KB
s3_18.txt AC 1 ms 384 KB
s3_19.txt AC 1 ms 384 KB
s3_20.txt AC 1 ms 384 KB
s3_21.txt AC 1 ms 256 KB
s3_22.txt AC 1 ms 384 KB
s3_23.txt AC 1 ms 384 KB
s3_24.txt AC 1 ms 128 KB
s3_25.txt AC 1 ms 384 KB
s3_26.txt AC 1 ms 384 KB
s4_27.txt AC 14 ms 1024 KB
s4_28.txt AC 4 ms 640 KB
s4_29.txt AC 75 ms 1664 KB
s4_30.txt AC 8 ms 768 KB
s4_31.txt AC 90 ms 1792 KB
s4_32.txt AC 93 ms 1792 KB
s4_33.txt AC 1 ms 128 KB
s4_34.txt AC 57 ms 1792 KB
s4_35.txt AC 57 ms 1792 KB
s4_36.txt AC 64 ms 1792 KB
s4_37.txt AC 89 ms 1792 KB