Submission #838454

# Submission time Handle Problem Language Result Execution time Memory
838454 2023-08-27T02:46:03 Z Charizard2021 Magneti (COCI21_magneti) C++17
110 / 110
106 ms 14924 KB
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long fact[100002], inv[100002];

long long pw(long long b, long long e)
{
	long long ans = 1;

	while(e)
	{
		if(e & 1)
			ans = (ans * b) % MOD;
		b = (b * b) % MOD;
		e >>= 1;
	}

	return ans;
}

long long C(long long n, long long k)
{
    if(n < k){
        return 0;
    }
	long long ans = fact[n];
	ans *= inv[k];
	ans %= MOD;
	ans *= inv[n-k];
	ans %= MOD;
	return ans;
}
int main(){
	fact[0] = 1;
	for(long long i = 1; i <= 100000; i++){
		fact[i] = (fact[i-1] * i) % MOD;
    }
	inv[0] = 1;
	for(long long i = 1; i <= 100000; i++){
		inv[i] = pw(fact[i], MOD-2);
	}
    long long n, l;
    cin >> n >> l;
    long long r[1 + n];
    for(long long i = 1; i <= n; i++){
        cin >> r[i];
    }
    sort(r + 1, r + n + 1);
    bool allEqual = true;
    for(long long i = 1; i < n; i++){
        if(r[i] != r[i + 1]){
            allEqual = false;
            break;
        }
    }
    if(allEqual){
	    cout << (fact[n] * C(l - (n - 1) * r[1] - 1 + n, n)) % MOD << "\n";
    }
    else{
        vector<vector<vector<long long> > > dp(2, vector<vector<long long> >(5 + n, vector<long long>(5 + l, 0)));
        dp[0][0][0] = 1;
        long long cur = 0;
        for(long long i = 1; i <= n; i++){
            cur ^= 1;
            dp[cur][0][0] = 0;
            long long rad = r[i];
            for(long long j = 1; j <= i; j++){
                for(long long k = 1; k <= l; k++){
                    dp[cur][j][k] = dp[!cur][j - 1][k - 1];
                    if(k >= rad){
                        dp[cur][j][k] = (dp[cur][j][k] + (dp[!cur][j][k - rad] * 2 * j) % MOD) % MOD;
                    }
                    if(k >= 2 * rad - 1){
                        dp[cur][j][k] = (dp[cur][j][k] + (dp[!cur][j + 1][k - 2 * rad + 1] * j * (j + 1)) % MOD) % MOD;
                    }
                }
            }
        }
        long long ans = 0;
        for(long long i = 1; i <= l; i++){
            ans = (ans + (dp[cur][1][i] * C(l - i + n, n)) % MOD) % MOD;
        }
        cout << ans << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1748 KB Output is correct
2 Correct 13 ms 1748 KB Output is correct
3 Correct 13 ms 1876 KB Output is correct
4 Correct 13 ms 1748 KB Output is correct
5 Correct 13 ms 1868 KB Output is correct
6 Correct 13 ms 1836 KB Output is correct
7 Correct 12 ms 1868 KB Output is correct
8 Correct 13 ms 1748 KB Output is correct
9 Correct 13 ms 1748 KB Output is correct
10 Correct 13 ms 1748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 5460 KB Output is correct
2 Correct 13 ms 2900 KB Output is correct
3 Correct 17 ms 5460 KB Output is correct
4 Correct 14 ms 3540 KB Output is correct
5 Correct 17 ms 5460 KB Output is correct
6 Correct 14 ms 3028 KB Output is correct
7 Correct 17 ms 5460 KB Output is correct
8 Correct 13 ms 2132 KB Output is correct
9 Correct 13 ms 3028 KB Output is correct
10 Correct 13 ms 1748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 2004 KB Output is correct
2 Correct 13 ms 2004 KB Output is correct
3 Correct 14 ms 2132 KB Output is correct
4 Correct 13 ms 2004 KB Output is correct
5 Correct 14 ms 2004 KB Output is correct
6 Correct 13 ms 1848 KB Output is correct
7 Correct 14 ms 2004 KB Output is correct
8 Correct 13 ms 1876 KB Output is correct
9 Correct 13 ms 2004 KB Output is correct
10 Correct 13 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1748 KB Output is correct
2 Correct 13 ms 1748 KB Output is correct
3 Correct 13 ms 1876 KB Output is correct
4 Correct 13 ms 1748 KB Output is correct
5 Correct 13 ms 1868 KB Output is correct
6 Correct 13 ms 1836 KB Output is correct
7 Correct 12 ms 1868 KB Output is correct
8 Correct 13 ms 1748 KB Output is correct
9 Correct 13 ms 1748 KB Output is correct
10 Correct 13 ms 1748 KB Output is correct
11 Correct 17 ms 5460 KB Output is correct
12 Correct 13 ms 2900 KB Output is correct
13 Correct 17 ms 5460 KB Output is correct
14 Correct 14 ms 3540 KB Output is correct
15 Correct 17 ms 5460 KB Output is correct
16 Correct 14 ms 3028 KB Output is correct
17 Correct 17 ms 5460 KB Output is correct
18 Correct 13 ms 2132 KB Output is correct
19 Correct 13 ms 3028 KB Output is correct
20 Correct 13 ms 1748 KB Output is correct
21 Correct 14 ms 2004 KB Output is correct
22 Correct 13 ms 2004 KB Output is correct
23 Correct 14 ms 2132 KB Output is correct
24 Correct 13 ms 2004 KB Output is correct
25 Correct 14 ms 2004 KB Output is correct
26 Correct 13 ms 1848 KB Output is correct
27 Correct 14 ms 2004 KB Output is correct
28 Correct 13 ms 1876 KB Output is correct
29 Correct 13 ms 2004 KB Output is correct
30 Correct 13 ms 1876 KB Output is correct
31 Correct 104 ms 14804 KB Output is correct
32 Correct 68 ms 10452 KB Output is correct
33 Correct 105 ms 14852 KB Output is correct
34 Correct 32 ms 6996 KB Output is correct
35 Correct 106 ms 14924 KB Output is correct
36 Correct 18 ms 4948 KB Output is correct
37 Correct 105 ms 14796 KB Output is correct
38 Correct 28 ms 3924 KB Output is correct
39 Correct 106 ms 14856 KB Output is correct
40 Correct 39 ms 9044 KB Output is correct
41 Correct 101 ms 14804 KB Output is correct
42 Correct 13 ms 2516 KB Output is correct
43 Correct 102 ms 14804 KB Output is correct
44 Correct 22 ms 5588 KB Output is correct
45 Correct 102 ms 14800 KB Output is correct
46 Correct 14 ms 3412 KB Output is correct
47 Correct 25 ms 8532 KB Output is correct
48 Correct 18 ms 4180 KB Output is correct
49 Correct 14 ms 4180 KB Output is correct
50 Correct 13 ms 1892 KB Output is correct