Submission #524151

# Submission time Handle Problem Language Result Execution time Memory
524151 2022-02-08T17:49:58 Z two_sides NoM (RMI21_nom) C++17
100 / 100
95 ms 452 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 4005;
const int MOD = 1e9 + 7;

int dp[2][N], fac[N], inv[N];

int add(int x, int y) {
    return (x += y) >= MOD ? x - MOD : x;
}

int sub(int x, int y) {
    return (x -= y) < 0 ? x + MOD : x;
}

int mul(int x, int y) {
    return (long long)x * y % MOD;
}

int bin(int n, int k) {
    if (n < k) return 0;
    return mul(fac[n], mul(inv[k], inv[n - k]));
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n, m; cin >> n >> m;
    fac[0] = inv[0] = inv[1] = 1;
    for (int i = 2; i < N; i++)
        inv[i] = MOD - mul(MOD / i, inv[MOD % i]);
    for (int i = 1; i < N; i++) {
        fac[i] = mul(fac[i - 1], i);
        inv[i] = mul(inv[i - 1], inv[i]);
    }
    dp[0][0] = 1;
    for (int i = 0; i < m; i++) {
        int l = (2 * n - i - 1) / m + 1;
        memset(dp[~i & 1], 0, sizeof dp[~i & 1]);
        for (int j = 0; j <= n; j++)
            for (int k = 0; k * 2 <= l && k <= j; k++)
                dp[~i & 1][j] = add(dp[~i & 1][j],
                mul(dp[i & 1][j - k], mul(bin(j, k),
                mul(fac[l], inv[l - 2 * k]))));
    }
    int res = 0;
    for (int i = 0; i <= n; i++) {
        int cur = mul(dp[m & 1][i], mul
        (bin(n, i), fac[2 * n - 2 * i]));
        if (i & 1) res = sub(res, cur);
        else res = add(res, cur);
    }
    cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 2 ms 316 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 308 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 5 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 2 ms 316 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 308 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 5 ms 452 KB Output is correct
28 Correct 5 ms 332 KB Output is correct
29 Correct 9 ms 332 KB Output is correct
30 Correct 10 ms 376 KB Output is correct
31 Correct 5 ms 312 KB Output is correct
32 Correct 9 ms 332 KB Output is correct
33 Correct 12 ms 332 KB Output is correct
34 Correct 20 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 2 ms 316 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 308 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 5 ms 452 KB Output is correct
28 Correct 5 ms 332 KB Output is correct
29 Correct 9 ms 332 KB Output is correct
30 Correct 10 ms 376 KB Output is correct
31 Correct 5 ms 312 KB Output is correct
32 Correct 9 ms 332 KB Output is correct
33 Correct 12 ms 332 KB Output is correct
34 Correct 20 ms 320 KB Output is correct
35 Correct 29 ms 332 KB Output is correct
36 Correct 75 ms 352 KB Output is correct
37 Correct 29 ms 332 KB Output is correct
38 Correct 48 ms 364 KB Output is correct
39 Correct 59 ms 352 KB Output is correct
40 Correct 95 ms 332 KB Output is correct