Submission #503709

# Submission time Handle Problem Language Result Execution time Memory
503709 2022-01-08T16:16:44 Z Stickfish NoM (RMI21_nom) C++17
100 / 100
50 ms 40376 KB
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;

const ll MOD = 1000000007;
const ll MAXN = 2077;

ll pw(ll a, ll m) {
    if (!m)
        return 1;
    a %= MOD;
    if (m % 2)
        return a * pw(a, m - 1) % MOD;
    return pw(a * a, m / 2);
}

ll fact[MAXN];
ll rfact[MAXN];

//ll choose(ll n, ll k) {
    //if (n < 0 || k < 0 || k > n)
        //return 0;
    //return 
//}

ll dp[MAXN][MAXN];
ll choose[MAXN][MAXN];

signed main() {
    fact[0] = rfact[0] = 1;
    for (int i = 1; i < MAXN; ++i) {
        fact[i] = (fact[i - 1] * i) % MOD;
        rfact[i] = pw(fact[i], MOD - 2);
    }
    for (int i = 0; i < MAXN; ++i) {
        for (int j = 0; j <= i; ++j) {
            choose[i][j] = (fact[i] * rfact[j] % MOD) * rfact[i - j] % MOD;
        }
    }
    int n, m;
    cin >> n >> m;
    if (m == 1) {
        cout << 0 << endl;
        return 0;
    }
    int sz = 2 * n / m;
    int szinc = 2 * n % m;
    int smsz = sz + int(0 < szinc);
    dp[0][0] = choose[n][smsz] * pw(2, n) % MOD;
    for (int i = 0; i < m; ++i) {
        dp[0][0] *= fact[sz + int(i < szinc)];
        dp[0][0] %= MOD;
    }
    for (int i = 1; i < m; ++i) {
        int szi = sz + int(i < szinc);
        for (int c = 0; c <= n; ++c) {
            for (int cp = max({0, smsz - n, c - szi}); cp <= c && smsz - cp * 2 >= 0; ++cp) {
                ll cnt1 = smsz - cp * 2;
                ll cnt0 = n + cp - smsz;
                if (szi - c + cp < 0)
                    continue;
                dp[i][c] += (dp[i - 1][cp] * choose[cnt1][c - cp] % MOD) * choose[cnt0][szi - (c - cp)];
                dp[i][c] %= MOD;
            }
            //cout << dp[i][c] << ' ';
        }
        smsz += szi;
        //cout << endl;
    }
    cout << dp[m - 1][n] % MOD << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 24524 KB Output is correct
2 Correct 19 ms 24524 KB Output is correct
3 Correct 15 ms 24512 KB Output is correct
4 Correct 15 ms 24540 KB Output is correct
5 Correct 16 ms 24440 KB Output is correct
6 Correct 17 ms 24440 KB Output is correct
7 Correct 16 ms 24488 KB Output is correct
8 Correct 16 ms 24452 KB Output is correct
9 Correct 16 ms 24524 KB Output is correct
10 Correct 16 ms 24500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 24524 KB Output is correct
2 Correct 19 ms 24524 KB Output is correct
3 Correct 15 ms 24512 KB Output is correct
4 Correct 15 ms 24540 KB Output is correct
5 Correct 16 ms 24440 KB Output is correct
6 Correct 17 ms 24440 KB Output is correct
7 Correct 16 ms 24488 KB Output is correct
8 Correct 16 ms 24452 KB Output is correct
9 Correct 16 ms 24524 KB Output is correct
10 Correct 16 ms 24500 KB Output is correct
11 Correct 19 ms 24644 KB Output is correct
12 Correct 17 ms 24780 KB Output is correct
13 Correct 16 ms 24500 KB Output is correct
14 Correct 16 ms 24600 KB Output is correct
15 Correct 16 ms 24780 KB Output is correct
16 Correct 16 ms 24560 KB Output is correct
17 Correct 16 ms 24676 KB Output is correct
18 Correct 16 ms 24668 KB Output is correct
19 Correct 15 ms 24496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 24524 KB Output is correct
2 Correct 19 ms 24524 KB Output is correct
3 Correct 15 ms 24512 KB Output is correct
4 Correct 15 ms 24540 KB Output is correct
5 Correct 16 ms 24440 KB Output is correct
6 Correct 17 ms 24440 KB Output is correct
7 Correct 16 ms 24488 KB Output is correct
8 Correct 16 ms 24452 KB Output is correct
9 Correct 16 ms 24524 KB Output is correct
10 Correct 16 ms 24500 KB Output is correct
11 Correct 19 ms 24644 KB Output is correct
12 Correct 17 ms 24780 KB Output is correct
13 Correct 16 ms 24500 KB Output is correct
14 Correct 16 ms 24600 KB Output is correct
15 Correct 16 ms 24780 KB Output is correct
16 Correct 16 ms 24560 KB Output is correct
17 Correct 16 ms 24676 KB Output is correct
18 Correct 16 ms 24668 KB Output is correct
19 Correct 15 ms 24496 KB Output is correct
20 Correct 16 ms 24580 KB Output is correct
21 Correct 16 ms 24800 KB Output is correct
22 Correct 17 ms 25652 KB Output is correct
23 Correct 16 ms 24524 KB Output is correct
24 Correct 16 ms 25164 KB Output is correct
25 Correct 17 ms 25548 KB Output is correct
26 Correct 16 ms 24588 KB Output is correct
27 Correct 19 ms 25884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 24524 KB Output is correct
2 Correct 19 ms 24524 KB Output is correct
3 Correct 15 ms 24512 KB Output is correct
4 Correct 15 ms 24540 KB Output is correct
5 Correct 16 ms 24440 KB Output is correct
6 Correct 17 ms 24440 KB Output is correct
7 Correct 16 ms 24488 KB Output is correct
8 Correct 16 ms 24452 KB Output is correct
9 Correct 16 ms 24524 KB Output is correct
10 Correct 16 ms 24500 KB Output is correct
11 Correct 19 ms 24644 KB Output is correct
12 Correct 17 ms 24780 KB Output is correct
13 Correct 16 ms 24500 KB Output is correct
14 Correct 16 ms 24600 KB Output is correct
15 Correct 16 ms 24780 KB Output is correct
16 Correct 16 ms 24560 KB Output is correct
17 Correct 16 ms 24676 KB Output is correct
18 Correct 16 ms 24668 KB Output is correct
19 Correct 15 ms 24496 KB Output is correct
20 Correct 16 ms 24580 KB Output is correct
21 Correct 16 ms 24800 KB Output is correct
22 Correct 17 ms 25652 KB Output is correct
23 Correct 16 ms 24524 KB Output is correct
24 Correct 16 ms 25164 KB Output is correct
25 Correct 17 ms 25548 KB Output is correct
26 Correct 16 ms 24588 KB Output is correct
27 Correct 19 ms 25884 KB Output is correct
28 Correct 18 ms 24588 KB Output is correct
29 Correct 18 ms 26160 KB Output is correct
30 Correct 20 ms 27568 KB Output is correct
31 Correct 18 ms 24488 KB Output is correct
32 Correct 19 ms 26312 KB Output is correct
33 Correct 21 ms 27980 KB Output is correct
34 Correct 23 ms 29692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 24524 KB Output is correct
2 Correct 19 ms 24524 KB Output is correct
3 Correct 15 ms 24512 KB Output is correct
4 Correct 15 ms 24540 KB Output is correct
5 Correct 16 ms 24440 KB Output is correct
6 Correct 17 ms 24440 KB Output is correct
7 Correct 16 ms 24488 KB Output is correct
8 Correct 16 ms 24452 KB Output is correct
9 Correct 16 ms 24524 KB Output is correct
10 Correct 16 ms 24500 KB Output is correct
11 Correct 19 ms 24644 KB Output is correct
12 Correct 17 ms 24780 KB Output is correct
13 Correct 16 ms 24500 KB Output is correct
14 Correct 16 ms 24600 KB Output is correct
15 Correct 16 ms 24780 KB Output is correct
16 Correct 16 ms 24560 KB Output is correct
17 Correct 16 ms 24676 KB Output is correct
18 Correct 16 ms 24668 KB Output is correct
19 Correct 15 ms 24496 KB Output is correct
20 Correct 16 ms 24580 KB Output is correct
21 Correct 16 ms 24800 KB Output is correct
22 Correct 17 ms 25652 KB Output is correct
23 Correct 16 ms 24524 KB Output is correct
24 Correct 16 ms 25164 KB Output is correct
25 Correct 17 ms 25548 KB Output is correct
26 Correct 16 ms 24588 KB Output is correct
27 Correct 19 ms 25884 KB Output is correct
28 Correct 18 ms 24588 KB Output is correct
29 Correct 18 ms 26160 KB Output is correct
30 Correct 20 ms 27568 KB Output is correct
31 Correct 18 ms 24488 KB Output is correct
32 Correct 19 ms 26312 KB Output is correct
33 Correct 21 ms 27980 KB Output is correct
34 Correct 23 ms 29692 KB Output is correct
35 Correct 27 ms 24620 KB Output is correct
36 Correct 42 ms 37324 KB Output is correct
37 Correct 28 ms 24644 KB Output is correct
38 Correct 32 ms 30404 KB Output is correct
39 Correct 37 ms 35348 KB Output is correct
40 Correct 50 ms 40376 KB Output is correct