Submission #858222

# Submission time Handle Problem Language Result Execution time Memory
858222 2023-10-07T16:14:31 Z thangdz2k7 NoM (RMI21_nom) C++17
34 / 100
500 ms 28968 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];

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;
}

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 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 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 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 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 11 ms 6488 KB Output is correct
12 Correct 6 ms 4440 KB Output is correct
13 Correct 5 ms 4444 KB Output is correct
14 Correct 5 ms 4444 KB Output is correct
15 Correct 6 ms 6492 KB Output is correct
16 Correct 8 ms 6492 KB Output is correct
17 Correct 5 ms 4444 KB Output is correct
18 Correct 5 ms 4444 KB Output is correct
19 Correct 8 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 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 11 ms 6488 KB Output is correct
12 Correct 6 ms 4440 KB Output is correct
13 Correct 5 ms 4444 KB Output is correct
14 Correct 5 ms 4444 KB Output is correct
15 Correct 6 ms 6492 KB Output is correct
16 Correct 8 ms 6492 KB Output is correct
17 Correct 5 ms 4444 KB Output is correct
18 Correct 5 ms 4444 KB Output is correct
19 Correct 8 ms 6492 KB Output is correct
20 Correct 27 ms 8540 KB Output is correct
21 Correct 25 ms 8700 KB Output is correct
22 Correct 71 ms 11604 KB Output is correct
23 Correct 59 ms 10580 KB Output is correct
24 Correct 92 ms 13064 KB Output is correct
25 Correct 68 ms 11512 KB Output is correct
26 Correct 67 ms 10756 KB Output is correct
27 Correct 90 ms 13820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 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 11 ms 6488 KB Output is correct
12 Correct 6 ms 4440 KB Output is correct
13 Correct 5 ms 4444 KB Output is correct
14 Correct 5 ms 4444 KB Output is correct
15 Correct 6 ms 6492 KB Output is correct
16 Correct 8 ms 6492 KB Output is correct
17 Correct 5 ms 4444 KB Output is correct
18 Correct 5 ms 4444 KB Output is correct
19 Correct 8 ms 6492 KB Output is correct
20 Correct 27 ms 8540 KB Output is correct
21 Correct 25 ms 8700 KB Output is correct
22 Correct 71 ms 11604 KB Output is correct
23 Correct 59 ms 10580 KB Output is correct
24 Correct 92 ms 13064 KB Output is correct
25 Correct 68 ms 11512 KB Output is correct
26 Correct 67 ms 10756 KB Output is correct
27 Correct 90 ms 13820 KB Output is correct
28 Correct 392 ms 23100 KB Output is correct
29 Correct 434 ms 24636 KB Output is correct
30 Correct 426 ms 26420 KB Output is correct
31 Correct 405 ms 23048 KB Output is correct
32 Correct 475 ms 26916 KB Output is correct
33 Execution timed out 517 ms 28968 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 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 11 ms 6488 KB Output is correct
12 Correct 6 ms 4440 KB Output is correct
13 Correct 5 ms 4444 KB Output is correct
14 Correct 5 ms 4444 KB Output is correct
15 Correct 6 ms 6492 KB Output is correct
16 Correct 8 ms 6492 KB Output is correct
17 Correct 5 ms 4444 KB Output is correct
18 Correct 5 ms 4444 KB Output is correct
19 Correct 8 ms 6492 KB Output is correct
20 Correct 27 ms 8540 KB Output is correct
21 Correct 25 ms 8700 KB Output is correct
22 Correct 71 ms 11604 KB Output is correct
23 Correct 59 ms 10580 KB Output is correct
24 Correct 92 ms 13064 KB Output is correct
25 Correct 68 ms 11512 KB Output is correct
26 Correct 67 ms 10756 KB Output is correct
27 Correct 90 ms 13820 KB Output is correct
28 Correct 392 ms 23100 KB Output is correct
29 Correct 434 ms 24636 KB Output is correct
30 Correct 426 ms 26420 KB Output is correct
31 Correct 405 ms 23048 KB Output is correct
32 Correct 475 ms 26916 KB Output is correct
33 Execution timed out 517 ms 28968 KB Time limit exceeded
34 Halted 0 ms 0 KB -