답안 #873919

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
873919 2023-11-16T02:44:30 Z noiaint Magneti (COCI21_magneti) C++17
110 / 110
105 ms 121692 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
 
#define getbit(x, i) (((x) >> (i)) & 1)
#define bit(x) (1 << (x))
#define popcount __builtin_popcountll
 
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
long long rand(long long l, long long r) {
    return l + rd() % (r - l + 1);
}
 
const int N = 1e6 + 5;
const int mod = 1e9 + 7; // 998244353;
const int lg = 25; // lg + 1
const int inf = 1e9; // INT_MAX;
const long long llinf = 1e18; // LLONG_MAX;
 
template<class X, class Y>
bool minimize(X &a, Y b) {
    return a > b ? (a = b, true) : false;
}
 
template<class X, class Y>
bool maximize(X &a, Y b) {
    return a < b ? (a = b, true) : false;
}
 
template<class X, class Y>
bool add(X &a, Y b) {
    a += b;
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return true;
}
 
const int MAX_N = 50 + 5;
const int MAX_L = 1e4 + 5;
 
int n, l;
int a[N];
int f[MAX_N][MAX_N][MAX_L];
 
int pw(int x, int y) {
    int res = 1;
    while (y) {
        if (y & 1) res = 1LL * res * x % mod;
        x = 1LL * x * x % mod;
        y >>= 1;
    }
    return res % mod;
}
int fac[N], inv[N];
void pre() {
    int n = 1e6;
    fac[0] = 1;
    for (int i = 1; i <= n; ++i) fac[i] = 1LL * fac[i - 1] * i % mod;
    inv[n] = pw(fac[n], mod - 2);
    for (int i = n; i >= 1; --i) inv[i - 1] = 1LL * inv[i] * i % mod;
}
int nCk(int n, int k) {
    if (k > n || k < 0) return 0;
    return 1LL * fac[n] * inv[k] % mod * inv[n - k] % mod;
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    pre();
 
    cin >> n >> l;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
 
    sort(a + 1, a + n + 1);
 
    f[0][0][0] = 1;
 
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= i; ++j)
            for (int k = 1; k <= l; ++k) {
                int r = a[i];
                // new component
                f[i][j][k] = f[i - 1][j - 1][k - 1];
 
                // append
                if (k - r >= 0)
                    add(f[i][j][k], 1LL * f[i - 1][j][k - r] * 2 * j % mod);
                
                // join
                // (r - 1) + (r - 1) + 1 = 2r - 1
                if (k - 2 * r + 1 >= 0)
                    add(f[i][j][k], 1LL * f[i - 1][j + 1][k - 2 * r + 1] * j * (j + 1) % mod);
            }
 
    int res = 0;
    for (int i = 1; i <= l; ++i)
        add(res, 1LL * f[n][1][i] * nCk(n + l - i, n) % mod);
 
    cout << res;
 
    return 0;
}
 
/*
 
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 121668 KB Output is correct
2 Correct 22 ms 121692 KB Output is correct
3 Correct 16 ms 35420 KB Output is correct
4 Correct 12 ms 20956 KB Output is correct
5 Correct 20 ms 57940 KB Output is correct
6 Correct 35 ms 72284 KB Output is correct
7 Correct 32 ms 117572 KB Output is correct
8 Correct 11 ms 12892 KB Output is correct
9 Correct 21 ms 90716 KB Output is correct
10 Correct 11 ms 12892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 33372 KB Output is correct
2 Correct 11 ms 16988 KB Output is correct
3 Correct 15 ms 33372 KB Output is correct
4 Correct 12 ms 21084 KB Output is correct
5 Correct 16 ms 33424 KB Output is correct
6 Correct 13 ms 25180 KB Output is correct
7 Correct 16 ms 33372 KB Output is correct
8 Correct 13 ms 33248 KB Output is correct
9 Correct 12 ms 23132 KB Output is correct
10 Correct 11 ms 12892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 76380 KB Output is correct
2 Correct 16 ms 56024 KB Output is correct
3 Correct 18 ms 76516 KB Output is correct
4 Correct 16 ms 57948 KB Output is correct
5 Correct 18 ms 76380 KB Output is correct
6 Correct 15 ms 53852 KB Output is correct
7 Correct 18 ms 76380 KB Output is correct
8 Correct 13 ms 33460 KB Output is correct
9 Correct 15 ms 57948 KB Output is correct
10 Correct 13 ms 33432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 121668 KB Output is correct
2 Correct 22 ms 121692 KB Output is correct
3 Correct 16 ms 35420 KB Output is correct
4 Correct 12 ms 20956 KB Output is correct
5 Correct 20 ms 57940 KB Output is correct
6 Correct 35 ms 72284 KB Output is correct
7 Correct 32 ms 117572 KB Output is correct
8 Correct 11 ms 12892 KB Output is correct
9 Correct 21 ms 90716 KB Output is correct
10 Correct 11 ms 12892 KB Output is correct
11 Correct 16 ms 33372 KB Output is correct
12 Correct 11 ms 16988 KB Output is correct
13 Correct 15 ms 33372 KB Output is correct
14 Correct 12 ms 21084 KB Output is correct
15 Correct 16 ms 33424 KB Output is correct
16 Correct 13 ms 25180 KB Output is correct
17 Correct 16 ms 33372 KB Output is correct
18 Correct 13 ms 33248 KB Output is correct
19 Correct 12 ms 23132 KB Output is correct
20 Correct 11 ms 12892 KB Output is correct
21 Correct 18 ms 76380 KB Output is correct
22 Correct 16 ms 56024 KB Output is correct
23 Correct 18 ms 76516 KB Output is correct
24 Correct 16 ms 57948 KB Output is correct
25 Correct 18 ms 76380 KB Output is correct
26 Correct 15 ms 53852 KB Output is correct
27 Correct 18 ms 76380 KB Output is correct
28 Correct 13 ms 33460 KB Output is correct
29 Correct 15 ms 57948 KB Output is correct
30 Correct 13 ms 33432 KB Output is correct
31 Correct 100 ms 121516 KB Output is correct
32 Correct 78 ms 111300 KB Output is correct
33 Correct 105 ms 121664 KB Output is correct
34 Correct 31 ms 70224 KB Output is correct
35 Correct 99 ms 121564 KB Output is correct
36 Correct 17 ms 41564 KB Output is correct
37 Correct 102 ms 121536 KB Output is correct
38 Correct 33 ms 117332 KB Output is correct
39 Correct 96 ms 121588 KB Output is correct
40 Correct 35 ms 72272 KB Output is correct
41 Correct 90 ms 121684 KB Output is correct
42 Correct 13 ms 29272 KB Output is correct
43 Correct 87 ms 121684 KB Output is correct
44 Correct 21 ms 53852 KB Output is correct
45 Correct 86 ms 121684 KB Output is correct
46 Correct 11 ms 14940 KB Output is correct
47 Correct 23 ms 78596 KB Output is correct
48 Correct 21 ms 94812 KB Output is correct
49 Correct 13 ms 27228 KB Output is correct
50 Correct 13 ms 35420 KB Output is correct