Submission #559844

# Submission time Handle Problem Language Result Execution time Memory
559844 2022-05-10T17:48:41 Z Alexandruabcde NoM (RMI21_nom) C++14
100 / 100
88 ms 59468 KB
#include <bits/stdc++.h>

using namespace std;

constexpr int NMAX = 2005;
constexpr int MOD = 1e9 + 7;

int N, M;
int Contor[NMAX];
int CntGrup[NMAX];

void Read () {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> M;

    for (int i = 1; i <= 2*N; ++ i )
        Contor[i%M + 1] ++;

    for (int i = 1; i <= M; ++ i )
        CntGrup[i] = CntGrup[i-1] + Contor[i];
}

int pow2[2*NMAX];
int fact[2*NMAX];
int Comb[2*NMAX][2*NMAX];

void Precompute () {
    fact[0] = 1;
    pow2[0] = 1;
    for (int i = 1; i <= 2*N; ++ i ) {
        fact[i] = (1LL * fact[i-1] * i) % MOD;
        pow2[i] = (1LL * pow2[i-1] * 2) % MOD;
    }

    Comb[0][0] = 1;
    for (int i = 1; i <= 2*N; ++ i ) {
        Comb[i][0] = Comb[i][i] = 1;

        for (int j = 1; j < i; ++ j )
            Comb[i][j] = (1LL * Comb[i-1][j-1] + 1LL * Comb[i-1][j]) % MOD;
    }
}

int dp[NMAX][NMAX];

void Solve () {
    dp[0][0] = 1;

    for (int grup = 0; grup < M; ++ grup ) {
        int Total = CntGrup[grup];
        for (int j = 0; j <= N && j <= Total; ++ j ) {
            int pairs = (Total - j) / 2;

            if (2 * pairs + j != Total) continue;

            int pos_new_jum = N - pairs - j;
            for (int complete = 0; complete <= j && complete <= Contor[grup+1]; ++ complete ) {
                int new_jum = Contor[grup+1] - complete;

                if (new_jum > pos_new_jum) continue;

                int coef = 1LL * Comb[pos_new_jum][new_jum] * pow2[new_jum] % MOD;
                coef = (1LL * coef * Comb[j][complete]) % MOD;
                coef = (1LL * coef * fact[Contor[grup+1]]) % MOD;

                dp[grup+1][j - complete + new_jum] = (dp[grup+1][j - complete + new_jum] + 1LL * coef * dp[grup][j] % MOD) % MOD;
            }
        }
    }

    cout << dp[M][0] << '\n';
}

int main()
{
    Read();
    Precompute();
    Solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 356 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 356 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 1364 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 980 KB Output is correct
15 Correct 1 ms 1228 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 356 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 1364 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 980 KB Output is correct
15 Correct 1 ms 1228 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 2 ms 1988 KB Output is correct
21 Correct 1 ms 2132 KB Output is correct
22 Correct 3 ms 4180 KB Output is correct
23 Correct 2 ms 2772 KB Output is correct
24 Correct 3 ms 4052 KB Output is correct
25 Correct 5 ms 3924 KB Output is correct
26 Correct 2 ms 2900 KB Output is correct
27 Correct 4 ms 4820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 356 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 1364 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 980 KB Output is correct
15 Correct 1 ms 1228 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 2 ms 1988 KB Output is correct
21 Correct 1 ms 2132 KB Output is correct
22 Correct 3 ms 4180 KB Output is correct
23 Correct 2 ms 2772 KB Output is correct
24 Correct 3 ms 4052 KB Output is correct
25 Correct 5 ms 3924 KB Output is correct
26 Correct 2 ms 2900 KB Output is correct
27 Correct 4 ms 4820 KB Output is correct
28 Correct 7 ms 8532 KB Output is correct
29 Correct 10 ms 10708 KB Output is correct
30 Correct 12 ms 11860 KB Output is correct
31 Correct 7 ms 8660 KB Output is correct
32 Correct 11 ms 11276 KB Output is correct
33 Correct 15 ms 13524 KB Output is correct
34 Correct 22 ms 19020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 356 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 1364 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 980 KB Output is correct
15 Correct 1 ms 1228 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 2 ms 1988 KB Output is correct
21 Correct 1 ms 2132 KB Output is correct
22 Correct 3 ms 4180 KB Output is correct
23 Correct 2 ms 2772 KB Output is correct
24 Correct 3 ms 4052 KB Output is correct
25 Correct 5 ms 3924 KB Output is correct
26 Correct 2 ms 2900 KB Output is correct
27 Correct 4 ms 4820 KB Output is correct
28 Correct 7 ms 8532 KB Output is correct
29 Correct 10 ms 10708 KB Output is correct
30 Correct 12 ms 11860 KB Output is correct
31 Correct 7 ms 8660 KB Output is correct
32 Correct 11 ms 11276 KB Output is correct
33 Correct 15 ms 13524 KB Output is correct
34 Correct 22 ms 19020 KB Output is correct
35 Correct 36 ms 34036 KB Output is correct
36 Correct 71 ms 50352 KB Output is correct
37 Correct 34 ms 33356 KB Output is correct
38 Correct 50 ms 40204 KB Output is correct
39 Correct 55 ms 42572 KB Output is correct
40 Correct 88 ms 59468 KB Output is correct