Submission #858221

# Submission time Handle Problem Language Result Execution time Memory
858221 2023-10-07T16:13:00 Z thangdz2k7 NoM (RMI21_nom) C++17
34 / 100
500 ms 69496 KB
#include <bits/stdc++.h>
#define int long long
#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];

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

void solve(){
    cin >> n >> m;
    gt[0] = 1;
    for (int i = 1; i <= 2 * n; ++ i) gt[i] = 1ll * gt[i - 1] * i % mod;
    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;
}

signed 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 1 ms 2652 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 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 1 ms 2652 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 11 ms 8544 KB Output is correct
12 Correct 6 ms 8540 KB Output is correct
13 Correct 5 ms 6492 KB Output is correct
14 Correct 6 ms 8540 KB Output is correct
15 Correct 6 ms 8540 KB Output is correct
16 Correct 8 ms 8540 KB Output is correct
17 Correct 5 ms 6488 KB Output is correct
18 Correct 5 ms 6492 KB Output is correct
19 Correct 8 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 11 ms 8544 KB Output is correct
12 Correct 6 ms 8540 KB Output is correct
13 Correct 5 ms 6492 KB Output is correct
14 Correct 6 ms 8540 KB Output is correct
15 Correct 6 ms 8540 KB Output is correct
16 Correct 8 ms 8540 KB Output is correct
17 Correct 5 ms 6488 KB Output is correct
18 Correct 5 ms 6492 KB Output is correct
19 Correct 8 ms 8540 KB Output is correct
20 Correct 26 ms 12636 KB Output is correct
21 Correct 24 ms 12796 KB Output is correct
22 Correct 69 ms 22100 KB Output is correct
23 Correct 53 ms 18772 KB Output is correct
24 Correct 83 ms 21508 KB Output is correct
25 Correct 61 ms 19964 KB Output is correct
26 Correct 59 ms 18776 KB Output is correct
27 Correct 87 ms 24580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 11 ms 8544 KB Output is correct
12 Correct 6 ms 8540 KB Output is correct
13 Correct 5 ms 6492 KB Output is correct
14 Correct 6 ms 8540 KB Output is correct
15 Correct 6 ms 8540 KB Output is correct
16 Correct 8 ms 8540 KB Output is correct
17 Correct 5 ms 6488 KB Output is correct
18 Correct 5 ms 6492 KB Output is correct
19 Correct 8 ms 8540 KB Output is correct
20 Correct 26 ms 12636 KB Output is correct
21 Correct 24 ms 12796 KB Output is correct
22 Correct 69 ms 22100 KB Output is correct
23 Correct 53 ms 18772 KB Output is correct
24 Correct 83 ms 21508 KB Output is correct
25 Correct 61 ms 19964 KB Output is correct
26 Correct 59 ms 18776 KB Output is correct
27 Correct 87 ms 24580 KB Output is correct
28 Correct 348 ms 43600 KB Output is correct
29 Correct 391 ms 47944 KB Output is correct
30 Correct 391 ms 48452 KB Output is correct
31 Correct 374 ms 43584 KB Output is correct
32 Correct 415 ms 48212 KB Output is correct
33 Correct 454 ms 53256 KB Output is correct
34 Execution timed out 730 ms 69496 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 11 ms 8544 KB Output is correct
12 Correct 6 ms 8540 KB Output is correct
13 Correct 5 ms 6492 KB Output is correct
14 Correct 6 ms 8540 KB Output is correct
15 Correct 6 ms 8540 KB Output is correct
16 Correct 8 ms 8540 KB Output is correct
17 Correct 5 ms 6488 KB Output is correct
18 Correct 5 ms 6492 KB Output is correct
19 Correct 8 ms 8540 KB Output is correct
20 Correct 26 ms 12636 KB Output is correct
21 Correct 24 ms 12796 KB Output is correct
22 Correct 69 ms 22100 KB Output is correct
23 Correct 53 ms 18772 KB Output is correct
24 Correct 83 ms 21508 KB Output is correct
25 Correct 61 ms 19964 KB Output is correct
26 Correct 59 ms 18776 KB Output is correct
27 Correct 87 ms 24580 KB Output is correct
28 Correct 348 ms 43600 KB Output is correct
29 Correct 391 ms 47944 KB Output is correct
30 Correct 391 ms 48452 KB Output is correct
31 Correct 374 ms 43584 KB Output is correct
32 Correct 415 ms 48212 KB Output is correct
33 Correct 454 ms 53256 KB Output is correct
34 Execution timed out 730 ms 69496 KB Time limit exceeded
35 Halted 0 ms 0 KB -