Submission #868919

# Submission time Handle Problem Language Result Execution time Memory
868919 2023-11-02T12:32:08 Z Cyber_Wolf Magneti (COCI21_magneti) C++17
110 / 110
279 ms 199848 KB
#include <bits/stdc++.h>

using namespace std;

#define lg long long 

const lg N = 2e5+5, MOD = 1e9+7;

lg v[N], fact[N];

lg fast_power(lg n, lg k)
{
	lg ans = 1;
	while(k)
	{
		if((k&1))
		{
			ans = (ans*n)%MOD;
		}
		n = (n*n)%MOD;
		k >>= 1;
	}
	return ans;
}

lg C(lg n, lg r)
{
	lg ans = fact[n];
	ans = (ans*fast_power(fact[r], MOD-2))%MOD;
	ans = (ans*fast_power(fact[n-r], MOD-2))%MOD;
	return ans;
}

lg dp[51][51][int(1e4+5)], fr[int(1e4+5)];

int main()
{
	lg n, l;
	cin >> n >> l;
	fact[0] = 1;
	for(lg i = 1; i <= 1e5; i++)	fact[i] = (fact[i-1]*i)%MOD;
	for(int i = 1; i <= n; i++)	cin >> v[i];
	sort(v+1, v+n+1);
	dp[1][1][1] = 1;
	for(int i = 1; i < n; i++)
	{
		for(int j = 1; j <= n; j++)
		{
			for(int k = 0; k <= l; k++)
			{
				if(k+v[i+1] <= 1e4)	dp[i+1][j][k+v[i+1]] = (dp[i+1][j][k+v[i+1]]+(dp[i][j][k]*j*2ll)%MOD)%MOD;
				if(j && k+v[i+1]*2 <= 1e4)	
				{
					dp[i+1][j-1][k+v[i+1]*2] = (dp[i+1][j-1][k+v[i+1]*2]+(dp[i][j][k]*(j*(j-1))%MOD)%MOD)%MOD;
				}
				dp[i+1][j+1][k] = (dp[i+1][j+1][k]+dp[i][j][k])%MOD; 
			}
		}
	}
	for(int i = 0; i <= l; i++)	fr[i] = dp[n][1][i];
	lg ans = 0;
	for(lg i = 0; i <= l; i++)
	{
		lg cur = fr[i];
		// cout << cur << ' ' << l-i+n << ' ' << n << '\n';
		cur = (cur*C(l-i+n, n))%MOD;
		ans = (ans+cur)%MOD;
	}
	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 279 ms 199732 KB Output is correct
2 Correct 7 ms 15704 KB Output is correct
3 Correct 12 ms 13400 KB Output is correct
4 Correct 5 ms 5980 KB Output is correct
5 Correct 15 ms 17220 KB Output is correct
6 Correct 71 ms 66448 KB Output is correct
7 Correct 144 ms 183632 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 67 ms 103768 KB Output is correct
10 Correct 2 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 12892 KB Output is correct
2 Correct 3 ms 5168 KB Output is correct
3 Correct 13 ms 12888 KB Output is correct
4 Correct 4 ms 5724 KB Output is correct
5 Correct 12 ms 12892 KB Output is correct
6 Correct 4 ms 6328 KB Output is correct
7 Correct 12 ms 12800 KB Output is correct
8 Correct 3 ms 5724 KB Output is correct
9 Correct 4 ms 6236 KB Output is correct
10 Correct 2 ms 4548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 10584 KB Output is correct
2 Correct 3 ms 7004 KB Output is correct
3 Correct 6 ms 10588 KB Output is correct
4 Correct 4 ms 7516 KB Output is correct
5 Correct 6 ms 10588 KB Output is correct
6 Correct 2 ms 6232 KB Output is correct
7 Correct 7 ms 10588 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 4 ms 8028 KB Output is correct
10 Correct 2 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 279 ms 199732 KB Output is correct
2 Correct 7 ms 15704 KB Output is correct
3 Correct 12 ms 13400 KB Output is correct
4 Correct 5 ms 5980 KB Output is correct
5 Correct 15 ms 17220 KB Output is correct
6 Correct 71 ms 66448 KB Output is correct
7 Correct 144 ms 183632 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 67 ms 103768 KB Output is correct
10 Correct 2 ms 4440 KB Output is correct
11 Correct 14 ms 12892 KB Output is correct
12 Correct 3 ms 5168 KB Output is correct
13 Correct 13 ms 12888 KB Output is correct
14 Correct 4 ms 5724 KB Output is correct
15 Correct 12 ms 12892 KB Output is correct
16 Correct 4 ms 6328 KB Output is correct
17 Correct 12 ms 12800 KB Output is correct
18 Correct 3 ms 5724 KB Output is correct
19 Correct 4 ms 6236 KB Output is correct
20 Correct 2 ms 4548 KB Output is correct
21 Correct 6 ms 10584 KB Output is correct
22 Correct 3 ms 7004 KB Output is correct
23 Correct 6 ms 10588 KB Output is correct
24 Correct 4 ms 7516 KB Output is correct
25 Correct 6 ms 10588 KB Output is correct
26 Correct 2 ms 6232 KB Output is correct
27 Correct 7 ms 10588 KB Output is correct
28 Correct 2 ms 5212 KB Output is correct
29 Correct 4 ms 8028 KB Output is correct
30 Correct 2 ms 5212 KB Output is correct
31 Correct 239 ms 199844 KB Output is correct
32 Correct 157 ms 137044 KB Output is correct
33 Correct 240 ms 199704 KB Output is correct
34 Correct 51 ms 49496 KB Output is correct
35 Correct 236 ms 199848 KB Output is correct
36 Correct 20 ms 17752 KB Output is correct
37 Correct 238 ms 199792 KB Output is correct
38 Correct 43 ms 46376 KB Output is correct
39 Correct 248 ms 199584 KB Output is correct
40 Correct 77 ms 66896 KB Output is correct
41 Correct 234 ms 199728 KB Output is correct
42 Correct 4 ms 6236 KB Output is correct
43 Correct 249 ms 199660 KB Output is correct
44 Correct 26 ms 26204 KB Output is correct
45 Correct 238 ms 199740 KB Output is correct
46 Correct 4 ms 4700 KB Output is correct
47 Correct 61 ms 78936 KB Output is correct
48 Correct 47 ms 63828 KB Output is correct
49 Correct 6 ms 8028 KB Output is correct
50 Correct 2 ms 5724 KB Output is correct