Submission #541156

# Submission time Handle Problem Language Result Execution time Memory
541156 2022-03-22T12:02:16 Z AlperenT Magneti (COCI21_magneti) C++17
110 / 110
201 ms 118892 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 50 + 5, S = 1e4 + 5, MOD = 1e9 + 7;

struct mint{
    int val = 0;
 
    mint(long long a = 0) : val(a % MOD) {if(val < 0) val += MOD; }
    mint(long long a, long long b) {*this += a; *this /= b; }
 
    mint &operator += (const mint &b) {val += b.val; if(val >= MOD) val -= MOD; return *this; }
    mint &operator -= (const mint &b) {val -= b.val; if(val < 0) val += MOD; return *this; }
    mint &operator *= (const mint &b) {val = (1ll * val * b.val) % MOD; return *this; }
 
    mint mexp(mint a, long long b){
        mint c(1);
        for(; b > 0; b /= 2, a *= a) if(b & 1) c *= a;
        return c;
    }
 
    mint minv(const mint &a) {return mexp(a, MOD - 2); };
 
    mint &operator /= (const mint &b) {*this *= minv(b); return *this; }
 
    friend mint operator + (mint a, const mint &b) {return a += b; }
    friend mint operator - (mint a, const mint &b) {return a -= b; }
    friend mint operator - (const mint &a) {return 0 - a; }
    friend mint operator * (mint a, const mint &b) {return a *= b; }
    friend mint operator / (mint a, const mint &b) {return a /= b; }
 
    friend bool operator == (const mint &a, const mint &b) {return a.val == b.val; }
    friend bool operator != (const mint &a, const mint &b) {return a.val != b.val; }
 
    friend istream &operator >> (istream &is, mint &a) {long long b; is >> b; a = b; return is; }
    friend ostream &operator << (ostream &os, const mint &a) {return os << a.val; }
};

int n, m, arr[N];

mint dp[N][N][S], fa[S], invfa[S], ans;

void precalc(){
    fa[0] = 1;
    for(int i = 1; i < S; i++) fa[i] = fa[i - 1] * i;

    invfa[S - 1] = mint().minv(fa[S - 1]);
    for(int i = S - 2; i >= 0; i--) invfa[i] = invfa[i + 1] * (i + 1);
}

mint calc(int stars, int bars){
    return fa[bars + stars] * (invfa[bars] * invfa[stars]);
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    precalc();

    cin >> n >> m;

    for(int i = 1; i <= n; i++) cin >> arr[i];

    sort(arr + 1, arr + n + 1);

    dp[0][0][0] = 1;

    for(int i = 0; i < n; i++){
        for(int j = 0; j <= i; j++){
            for(int k = 0; k <= m; k++){
                if(k + 1 <= m) dp[i + 1][j + 1][k + 1] += dp[i][j][k];
                if(k + arr[i + 1] <= m && j >= 1) dp[i + 1][j][k + arr[i + 1]] += dp[i][j][k] * j * 2;
                if(k + (arr[i + 1] * 2 - 1) <= m && j >= 2) dp[i + 1][j - 1][k + (arr[i + 1] * 2 - 1)] += dp[i][j][k] * j * (j - 1);
            }
        }
    }

    for(int i = 0; i <= m; i++) ans += dp[n][1][i] * calc(m - i, n);

    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 170 ms 118840 KB Output is correct
2 Correct 50 ms 118752 KB Output is correct
3 Correct 58 ms 118720 KB Output is correct
4 Correct 55 ms 118816 KB Output is correct
5 Correct 62 ms 118732 KB Output is correct
6 Correct 82 ms 118732 KB Output is correct
7 Correct 76 ms 118772 KB Output is correct
8 Correct 51 ms 118772 KB Output is correct
9 Correct 68 ms 118764 KB Output is correct
10 Correct 61 ms 118732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 118756 KB Output is correct
2 Correct 53 ms 118760 KB Output is correct
3 Correct 54 ms 118736 KB Output is correct
4 Correct 60 ms 118732 KB Output is correct
5 Correct 67 ms 118752 KB Output is correct
6 Correct 58 ms 118856 KB Output is correct
7 Correct 63 ms 118732 KB Output is correct
8 Correct 50 ms 118808 KB Output is correct
9 Correct 50 ms 118820 KB Output is correct
10 Correct 58 ms 118724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 118756 KB Output is correct
2 Correct 54 ms 118832 KB Output is correct
3 Correct 65 ms 118752 KB Output is correct
4 Correct 51 ms 118712 KB Output is correct
5 Correct 51 ms 118732 KB Output is correct
6 Correct 55 ms 118836 KB Output is correct
7 Correct 52 ms 118736 KB Output is correct
8 Correct 55 ms 118892 KB Output is correct
9 Correct 52 ms 118728 KB Output is correct
10 Correct 59 ms 118784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 170 ms 118840 KB Output is correct
2 Correct 50 ms 118752 KB Output is correct
3 Correct 58 ms 118720 KB Output is correct
4 Correct 55 ms 118816 KB Output is correct
5 Correct 62 ms 118732 KB Output is correct
6 Correct 82 ms 118732 KB Output is correct
7 Correct 76 ms 118772 KB Output is correct
8 Correct 51 ms 118772 KB Output is correct
9 Correct 68 ms 118764 KB Output is correct
10 Correct 61 ms 118732 KB Output is correct
11 Correct 57 ms 118756 KB Output is correct
12 Correct 53 ms 118760 KB Output is correct
13 Correct 54 ms 118736 KB Output is correct
14 Correct 60 ms 118732 KB Output is correct
15 Correct 67 ms 118752 KB Output is correct
16 Correct 58 ms 118856 KB Output is correct
17 Correct 63 ms 118732 KB Output is correct
18 Correct 50 ms 118808 KB Output is correct
19 Correct 50 ms 118820 KB Output is correct
20 Correct 58 ms 118724 KB Output is correct
21 Correct 54 ms 118756 KB Output is correct
22 Correct 54 ms 118832 KB Output is correct
23 Correct 65 ms 118752 KB Output is correct
24 Correct 51 ms 118712 KB Output is correct
25 Correct 51 ms 118732 KB Output is correct
26 Correct 55 ms 118836 KB Output is correct
27 Correct 52 ms 118736 KB Output is correct
28 Correct 55 ms 118892 KB Output is correct
29 Correct 52 ms 118728 KB Output is correct
30 Correct 59 ms 118784 KB Output is correct
31 Correct 180 ms 118832 KB Output is correct
32 Correct 130 ms 118732 KB Output is correct
33 Correct 201 ms 118740 KB Output is correct
34 Correct 81 ms 118784 KB Output is correct
35 Correct 182 ms 118728 KB Output is correct
36 Correct 67 ms 118800 KB Output is correct
37 Correct 191 ms 118732 KB Output is correct
38 Correct 76 ms 118836 KB Output is correct
39 Correct 181 ms 118836 KB Output is correct
40 Correct 86 ms 118732 KB Output is correct
41 Correct 174 ms 118836 KB Output is correct
42 Correct 51 ms 118784 KB Output is correct
43 Correct 186 ms 118832 KB Output is correct
44 Correct 62 ms 118752 KB Output is correct
45 Correct 169 ms 118836 KB Output is correct
46 Correct 50 ms 118824 KB Output is correct
47 Correct 65 ms 118820 KB Output is correct
48 Correct 60 ms 118804 KB Output is correct
49 Correct 64 ms 118796 KB Output is correct
50 Correct 50 ms 118784 KB Output is correct