Submission #858226

# Submission time Handle Problem Language Result Execution time Memory
858226 2023-10-07T16:17:38 Z thangdz2k7 NoM (RMI21_nom) C++17
100 / 100
112 ms 87124 KB
#include <bits/stdc++.h>
#define ii pair <int, int>
#define F first
#define S second

using namespace std;

const int mod = 1e9 + 7;
const int N = 4e3 + 5;

void add(int &a, int b){
    a += b;
    if (a >= mod) a -= mod;
    if (a < 0) a += mod;
}

int mu(int a, int b){
    if (b == 0) return 1;
    if (b % 2 == 1) return 1ll * mu(a, b - 1) * a % mod;
    int c = mu(a, b / 2);
    return 1ll * c * c % mod;
}

int dp[N][N], C[N][N];
int n, m;
int gt[N], re_2[N], re_gt[N];

int c(int b, int a){
    return 1ll * (1ll * gt[a] * re_gt[b] % mod) * re_gt[a - b] % mod;
}

void solve(){
    cin >> n >> m;
    gt[0] = 1;
    re_gt[0] = 1;
    for (int i = 1; i <= 2 * n; ++ i) {
        gt[i] = 1ll * gt[i - 1] * i % mod;
        re_gt[i] = mu(gt[i], mod - 2);
    }
    int kk = mu(2, mod - 2);
    re_2[0] = 1;
    for (int i = 1; i <= n; ++ i) re_2[i] = 1ll * re_2[i - 1] * kk % mod;

    for (int i = 0; i <= 2 * n; ++ i) for (int j = 0; j <= i; ++ j) C[j][i] = c(j, i);

    dp[0][0] = 1;
    for (int i = 1; i <= m; ++ i){
        int val = (2 * n - i) / m + 1;
        for (int j = 0; j <= n; ++ j){
            //dp[i][j] = dp[i - 1][j];
            for (int k = 0; k <= min(j, val / 2); ++ k){
                int zk = 1ll * dp[i - 1][j - k] * C[2 * k][val] % mod;
                //zk = 1ll * zk * re_2[k] % mod;
                zk = 1ll * zk * gt[2 * k] % mod;
                zk = 1ll * zk * C[k][n - j + k] % mod;
                add(dp[i][j], zk);
            }
            //cout << dp[i][j] << ' ';
        }
        //cout << endl;
    }

    int ans = 0;
    for (int i = 0; i <= n; ++ i){
        int val = 1ll * dp[m][i] * gt[(n - i) * 2] % mod;
        //val = 1ll * val * re_2[n - i] % mod;
        if (i % 2 == 0) add(ans, val);
        else add(ans, -val);
    }

    cout << ans;
}

int main(){
    //freopen("code.inp", "r", stdin);
    //freopen("code.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    while (t --) solve();

    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 4608 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 4608 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 2 ms 8536 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 3 ms 11612 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 4 ms 13148 KB Output is correct
25 Correct 3 ms 11612 KB Output is correct
26 Correct 2 ms 10584 KB Output is correct
27 Correct 4 ms 13916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 4608 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 2 ms 8536 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 3 ms 11612 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 4 ms 13148 KB Output is correct
25 Correct 3 ms 11612 KB Output is correct
26 Correct 2 ms 10584 KB Output is correct
27 Correct 4 ms 13916 KB Output is correct
28 Correct 9 ms 22960 KB Output is correct
29 Correct 12 ms 24864 KB Output is correct
30 Correct 15 ms 26456 KB Output is correct
31 Correct 9 ms 22876 KB Output is correct
32 Correct 13 ms 27044 KB Output is correct
33 Correct 15 ms 29096 KB Output is correct
34 Correct 25 ms 37468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 4608 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 2 ms 8536 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 3 ms 11612 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 4 ms 13148 KB Output is correct
25 Correct 3 ms 11612 KB Output is correct
26 Correct 2 ms 10584 KB Output is correct
27 Correct 4 ms 13916 KB Output is correct
28 Correct 9 ms 22960 KB Output is correct
29 Correct 12 ms 24864 KB Output is correct
30 Correct 15 ms 26456 KB Output is correct
31 Correct 9 ms 22876 KB Output is correct
32 Correct 13 ms 27044 KB Output is correct
33 Correct 15 ms 29096 KB Output is correct
34 Correct 25 ms 37468 KB Output is correct
35 Correct 46 ms 53940 KB Output is correct
36 Correct 86 ms 77912 KB Output is correct
37 Correct 46 ms 53964 KB Output is correct
38 Correct 62 ms 63704 KB Output is correct
39 Correct 68 ms 68436 KB Output is correct
40 Correct 112 ms 87124 KB Output is correct