Submission #857082

# Submission time Handle Problem Language Result Execution time Memory
857082 2023-10-05T11:03:49 Z lolismek NoM (RMI21_nom) C++14
100 / 100
113 ms 63036 KB
#include <iostream>

#define int long long

using namespace std;

const int NMAX = 2000;
const int MOD = 1e9 + 7;

int dp[NMAX + 1][NMAX + 1];
int sz[NMAX + 1];
int s[NMAX + 1];

int comb[NMAX + 1][NMAX + 1];
int fact[NMAX + 1];

int C(int n, int k){
    if(n < 0 || k < 0 || k > n){
        return 0;
    }

    return comb[n][k];
}

int f(int s, int j){
    if((s - j) % 2 == 1){
        return -1;
    }

    return j + ((s - j) / 2);
}

signed main(){

    comb[0][0] = 1;
    for(int i = 1; i <= NMAX; i++){
        comb[i][0] = 1;
        for(int j = 1; j <= NMAX; j++){
            comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % MOD;
        }
    }

    int n, m;
    cin >> n >> m;

    n *= 2;
    for(int i = 1; i <= m; i++){
        for(int j = i; j <= n; j += m){
            sz[i]++;
        }
        s[i] = s[i - 1] + sz[i];
    }
    n /= 2;

    dp[1][sz[1]] = C(n, sz[1]);
    for(int i = 1; i <= m - 1; i++){
        for(int j = 0; j <= n; j++){
            for(int k = 0; k <= min(j, sz[i + 1]); k++){
                int newJ = j - k + (sz[i + 1] - k);
                if(newJ > n){
                    continue;
                }

                int r = n - f(s[i] + k, j - k);
                if(r == -1){
                    continue;
                }
                (dp[i + 1][newJ] += ((dp[i][j] * C(j, k)) % MOD * C(r, sz[i + 1] - k)) % MOD) %= MOD;
            }
        }
    }
    
    int ans = dp[m][0];

    fact[0] = 1;
    for(int i = 1; i <= 2 * n; i++){
        (fact[i] = fact[i - 1] * i) %= MOD;
    }

    int pw = 1;
    for(int i = 1; i <= n; i++){
        (pw *= 2) %= MOD;
    }

    ans = (ans * pw) % MOD;

    for(int i = 1; i <= m; i++){
        (ans *= fact[sz[i]]) %= MOD;
    }

    cout << ans <<'\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 33420 KB Output is correct
2 Correct 10 ms 33372 KB Output is correct
3 Correct 10 ms 33372 KB Output is correct
4 Correct 9 ms 33380 KB Output is correct
5 Correct 9 ms 33372 KB Output is correct
6 Correct 9 ms 33416 KB Output is correct
7 Correct 10 ms 33372 KB Output is correct
8 Correct 10 ms 33372 KB Output is correct
9 Correct 9 ms 33372 KB Output is correct
10 Correct 9 ms 33372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 33420 KB Output is correct
2 Correct 10 ms 33372 KB Output is correct
3 Correct 10 ms 33372 KB Output is correct
4 Correct 9 ms 33380 KB Output is correct
5 Correct 9 ms 33372 KB Output is correct
6 Correct 9 ms 33416 KB Output is correct
7 Correct 10 ms 33372 KB Output is correct
8 Correct 10 ms 33372 KB Output is correct
9 Correct 9 ms 33372 KB Output is correct
10 Correct 9 ms 33372 KB Output is correct
11 Correct 9 ms 33372 KB Output is correct
12 Correct 9 ms 33372 KB Output is correct
13 Correct 9 ms 33372 KB Output is correct
14 Correct 10 ms 33372 KB Output is correct
15 Correct 9 ms 33368 KB Output is correct
16 Correct 9 ms 33372 KB Output is correct
17 Correct 9 ms 33412 KB Output is correct
18 Correct 10 ms 33332 KB Output is correct
19 Correct 10 ms 33424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 33420 KB Output is correct
2 Correct 10 ms 33372 KB Output is correct
3 Correct 10 ms 33372 KB Output is correct
4 Correct 9 ms 33380 KB Output is correct
5 Correct 9 ms 33372 KB Output is correct
6 Correct 9 ms 33416 KB Output is correct
7 Correct 10 ms 33372 KB Output is correct
8 Correct 10 ms 33372 KB Output is correct
9 Correct 9 ms 33372 KB Output is correct
10 Correct 9 ms 33372 KB Output is correct
11 Correct 9 ms 33372 KB Output is correct
12 Correct 9 ms 33372 KB Output is correct
13 Correct 9 ms 33372 KB Output is correct
14 Correct 10 ms 33372 KB Output is correct
15 Correct 9 ms 33368 KB Output is correct
16 Correct 9 ms 33372 KB Output is correct
17 Correct 9 ms 33412 KB Output is correct
18 Correct 10 ms 33332 KB Output is correct
19 Correct 10 ms 33424 KB Output is correct
20 Correct 10 ms 33368 KB Output is correct
21 Correct 10 ms 33424 KB Output is correct
22 Correct 11 ms 34164 KB Output is correct
23 Correct 11 ms 33376 KB Output is correct
24 Correct 10 ms 33636 KB Output is correct
25 Correct 10 ms 34148 KB Output is correct
26 Correct 10 ms 33448 KB Output is correct
27 Correct 11 ms 34664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 33420 KB Output is correct
2 Correct 10 ms 33372 KB Output is correct
3 Correct 10 ms 33372 KB Output is correct
4 Correct 9 ms 33380 KB Output is correct
5 Correct 9 ms 33372 KB Output is correct
6 Correct 9 ms 33416 KB Output is correct
7 Correct 10 ms 33372 KB Output is correct
8 Correct 10 ms 33372 KB Output is correct
9 Correct 9 ms 33372 KB Output is correct
10 Correct 9 ms 33372 KB Output is correct
11 Correct 9 ms 33372 KB Output is correct
12 Correct 9 ms 33372 KB Output is correct
13 Correct 9 ms 33372 KB Output is correct
14 Correct 10 ms 33372 KB Output is correct
15 Correct 9 ms 33368 KB Output is correct
16 Correct 9 ms 33372 KB Output is correct
17 Correct 9 ms 33412 KB Output is correct
18 Correct 10 ms 33332 KB Output is correct
19 Correct 10 ms 33424 KB Output is correct
20 Correct 10 ms 33368 KB Output is correct
21 Correct 10 ms 33424 KB Output is correct
22 Correct 11 ms 34164 KB Output is correct
23 Correct 11 ms 33376 KB Output is correct
24 Correct 10 ms 33636 KB Output is correct
25 Correct 10 ms 34148 KB Output is correct
26 Correct 10 ms 33448 KB Output is correct
27 Correct 11 ms 34664 KB Output is correct
28 Correct 15 ms 33380 KB Output is correct
29 Correct 18 ms 35236 KB Output is correct
30 Correct 24 ms 37604 KB Output is correct
31 Correct 13 ms 33384 KB Output is correct
32 Correct 17 ms 35688 KB Output is correct
33 Correct 24 ms 38504 KB Output is correct
34 Correct 30 ms 42036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 33420 KB Output is correct
2 Correct 10 ms 33372 KB Output is correct
3 Correct 10 ms 33372 KB Output is correct
4 Correct 9 ms 33380 KB Output is correct
5 Correct 9 ms 33372 KB Output is correct
6 Correct 9 ms 33416 KB Output is correct
7 Correct 10 ms 33372 KB Output is correct
8 Correct 10 ms 33372 KB Output is correct
9 Correct 9 ms 33372 KB Output is correct
10 Correct 9 ms 33372 KB Output is correct
11 Correct 9 ms 33372 KB Output is correct
12 Correct 9 ms 33372 KB Output is correct
13 Correct 9 ms 33372 KB Output is correct
14 Correct 10 ms 33372 KB Output is correct
15 Correct 9 ms 33368 KB Output is correct
16 Correct 9 ms 33372 KB Output is correct
17 Correct 9 ms 33412 KB Output is correct
18 Correct 10 ms 33332 KB Output is correct
19 Correct 10 ms 33424 KB Output is correct
20 Correct 10 ms 33368 KB Output is correct
21 Correct 10 ms 33424 KB Output is correct
22 Correct 11 ms 34164 KB Output is correct
23 Correct 11 ms 33376 KB Output is correct
24 Correct 10 ms 33636 KB Output is correct
25 Correct 10 ms 34148 KB Output is correct
26 Correct 10 ms 33448 KB Output is correct
27 Correct 11 ms 34664 KB Output is correct
28 Correct 15 ms 33380 KB Output is correct
29 Correct 18 ms 35236 KB Output is correct
30 Correct 24 ms 37604 KB Output is correct
31 Correct 13 ms 33384 KB Output is correct
32 Correct 17 ms 35688 KB Output is correct
33 Correct 24 ms 38504 KB Output is correct
34 Correct 30 ms 42036 KB Output is correct
35 Correct 44 ms 33440 KB Output is correct
36 Correct 96 ms 58212 KB Output is correct
37 Correct 43 ms 33436 KB Output is correct
38 Correct 58 ms 44628 KB Output is correct
39 Correct 75 ms 55136 KB Output is correct
40 Correct 113 ms 63036 KB Output is correct