Submission #551819

# Submission time Handle Problem Language Result Execution time Memory
551819 2022-04-21T16:12:43 Z Hanksburger Tents (JOI18_tents) C++17
100 / 100
110 ms 71088 KB
#include <bits/stdc++.h>
using namespace std;
const long long mod=1000000007, half=500000004;
long long dp[3005][3005], fac[3005], invfac[3005], invpow[3005];
long long power(long long a, long long b)
{
	if (!b)
		return 1;
	long long res=power(a, b/2);
	if (b&1)
		return res*res%mod*a%mod;
	else
		return res*res%mod;
}
long long nCr(long long n, long long r)
{
	return fac[n]*invfac[r]%mod*invfac[n-r]%mod;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	fac[0]=1;
	for (long long i=1; i<=3000; i++)
		fac[i]=fac[i-1]*i%mod;
	invfac[3000]=power(fac[3000], mod-2);
	for (long long i=2999; i>=0; i--)
		invfac[i]=invfac[i+1]*(i+1)%mod;
	invpow[0]=1;
	for (long long i=1; i<=3000; i++)
		invpow[i]=invpow[i-1]*half%mod;
	for (long long i=0; i<=3000; i++)
		dp[0][i]=1;
	for (long long i=1; i<=3000; i++)
		dp[i][0]=1;
	for (long long i=1; i<=3000; i++)
		for (long long j=1; j<=3000; j++)
			dp[i][j]=(dp[i-1][j-1]*j*4+dp[i-1][j])%mod;
	long long n, m, ans=0;
	cin >> n >> m;
	for (long long i=0; i<=min(n, m/2); i++)
	{
		for (long long j=0; j<=min((n-i)/2, m-i*2); j++)
		{
			long long num1=nCr(n, i);
			long long num2=fac[m]*invfac[m-i*2]%mod*invpow[i]%mod;
			long long num3=nCr(m-i*2, j);
			long long num4=fac[n-i]*invfac[n-i-j*2]%mod*invpow[j]%mod;
			ans=(ans+num1*num2%mod*num3%mod*num4%mod*dp[n-i-j*2][m-i*2-j])%mod;
		}
	}
	cout << ans-1;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 42 ms 70884 KB Output is correct
2 Correct 44 ms 70960 KB Output is correct
3 Correct 52 ms 70876 KB Output is correct
4 Correct 42 ms 70868 KB Output is correct
5 Correct 40 ms 70876 KB Output is correct
6 Correct 43 ms 70968 KB Output is correct
7 Correct 42 ms 70868 KB Output is correct
8 Correct 44 ms 70932 KB Output is correct
9 Correct 57 ms 70860 KB Output is correct
10 Correct 53 ms 70936 KB Output is correct
11 Correct 51 ms 70856 KB Output is correct
12 Correct 40 ms 70948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 70884 KB Output is correct
2 Correct 44 ms 70960 KB Output is correct
3 Correct 52 ms 70876 KB Output is correct
4 Correct 42 ms 70868 KB Output is correct
5 Correct 40 ms 70876 KB Output is correct
6 Correct 43 ms 70968 KB Output is correct
7 Correct 42 ms 70868 KB Output is correct
8 Correct 44 ms 70932 KB Output is correct
9 Correct 57 ms 70860 KB Output is correct
10 Correct 53 ms 70936 KB Output is correct
11 Correct 51 ms 70856 KB Output is correct
12 Correct 40 ms 70948 KB Output is correct
13 Correct 43 ms 70872 KB Output is correct
14 Correct 42 ms 71000 KB Output is correct
15 Correct 100 ms 70968 KB Output is correct
16 Correct 47 ms 70868 KB Output is correct
17 Correct 46 ms 70948 KB Output is correct
18 Correct 48 ms 70968 KB Output is correct
19 Correct 84 ms 70968 KB Output is correct
20 Correct 78 ms 70976 KB Output is correct
21 Correct 56 ms 70952 KB Output is correct
22 Correct 64 ms 70976 KB Output is correct
23 Correct 44 ms 70888 KB Output is correct
24 Correct 109 ms 70972 KB Output is correct
25 Correct 93 ms 70976 KB Output is correct
26 Correct 110 ms 71088 KB Output is correct
27 Correct 106 ms 70968 KB Output is correct