Submission #503708

# Submission time Handle Problem Language Result Execution time Memory
503708 2022-01-08T16:12:26 Z Stickfish NoM (RMI21_nom) C++17
52 / 100
500 ms 29796 KB
#include <iostream>
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 = 0; cp <= c; ++cp) {
                ll cnt1 = smsz - cp * 2;
                ll cnt0 = n + cp - smsz;
                if (cnt1 < 0 || cnt0 < 0 || 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 20 ms 24488 KB Output is correct
3 Correct 16 ms 24464 KB Output is correct
4 Correct 16 ms 24524 KB Output is correct
5 Correct 17 ms 24464 KB Output is correct
6 Correct 17 ms 24480 KB Output is correct
7 Correct 17 ms 24532 KB Output is correct
8 Correct 20 ms 24524 KB Output is correct
9 Correct 22 ms 24524 KB Output is correct
10 Correct 15 ms 24468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 24524 KB Output is correct
2 Correct 20 ms 24488 KB Output is correct
3 Correct 16 ms 24464 KB Output is correct
4 Correct 16 ms 24524 KB Output is correct
5 Correct 17 ms 24464 KB Output is correct
6 Correct 17 ms 24480 KB Output is correct
7 Correct 17 ms 24532 KB Output is correct
8 Correct 20 ms 24524 KB Output is correct
9 Correct 22 ms 24524 KB Output is correct
10 Correct 15 ms 24468 KB Output is correct
11 Correct 17 ms 24752 KB Output is correct
12 Correct 17 ms 24696 KB Output is correct
13 Correct 16 ms 24476 KB Output is correct
14 Correct 16 ms 24636 KB Output is correct
15 Correct 16 ms 24772 KB Output is correct
16 Correct 16 ms 24472 KB Output is correct
17 Correct 17 ms 24636 KB Output is correct
18 Correct 17 ms 24652 KB Output is correct
19 Correct 20 ms 24484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 24524 KB Output is correct
2 Correct 20 ms 24488 KB Output is correct
3 Correct 16 ms 24464 KB Output is correct
4 Correct 16 ms 24524 KB Output is correct
5 Correct 17 ms 24464 KB Output is correct
6 Correct 17 ms 24480 KB Output is correct
7 Correct 17 ms 24532 KB Output is correct
8 Correct 20 ms 24524 KB Output is correct
9 Correct 22 ms 24524 KB Output is correct
10 Correct 15 ms 24468 KB Output is correct
11 Correct 17 ms 24752 KB Output is correct
12 Correct 17 ms 24696 KB Output is correct
13 Correct 16 ms 24476 KB Output is correct
14 Correct 16 ms 24636 KB Output is correct
15 Correct 16 ms 24772 KB Output is correct
16 Correct 16 ms 24472 KB Output is correct
17 Correct 17 ms 24636 KB Output is correct
18 Correct 17 ms 24652 KB Output is correct
19 Correct 20 ms 24484 KB Output is correct
20 Correct 17 ms 24608 KB Output is correct
21 Correct 20 ms 24856 KB Output is correct
22 Correct 29 ms 25664 KB Output is correct
23 Correct 17 ms 24524 KB Output is correct
24 Correct 25 ms 25156 KB Output is correct
25 Correct 29 ms 25628 KB Output is correct
26 Correct 17 ms 24512 KB Output is correct
27 Correct 35 ms 25804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 24524 KB Output is correct
2 Correct 20 ms 24488 KB Output is correct
3 Correct 16 ms 24464 KB Output is correct
4 Correct 16 ms 24524 KB Output is correct
5 Correct 17 ms 24464 KB Output is correct
6 Correct 17 ms 24480 KB Output is correct
7 Correct 17 ms 24532 KB Output is correct
8 Correct 20 ms 24524 KB Output is correct
9 Correct 22 ms 24524 KB Output is correct
10 Correct 15 ms 24468 KB Output is correct
11 Correct 17 ms 24752 KB Output is correct
12 Correct 17 ms 24696 KB Output is correct
13 Correct 16 ms 24476 KB Output is correct
14 Correct 16 ms 24636 KB Output is correct
15 Correct 16 ms 24772 KB Output is correct
16 Correct 16 ms 24472 KB Output is correct
17 Correct 17 ms 24636 KB Output is correct
18 Correct 17 ms 24652 KB Output is correct
19 Correct 20 ms 24484 KB Output is correct
20 Correct 17 ms 24608 KB Output is correct
21 Correct 20 ms 24856 KB Output is correct
22 Correct 29 ms 25664 KB Output is correct
23 Correct 17 ms 24524 KB Output is correct
24 Correct 25 ms 25156 KB Output is correct
25 Correct 29 ms 25628 KB Output is correct
26 Correct 17 ms 24512 KB Output is correct
27 Correct 35 ms 25804 KB Output is correct
28 Correct 25 ms 24636 KB Output is correct
29 Correct 111 ms 26188 KB Output is correct
30 Correct 205 ms 27652 KB Output is correct
31 Correct 26 ms 24524 KB Output is correct
32 Correct 120 ms 26308 KB Output is correct
33 Correct 254 ms 27992 KB Output is correct
34 Correct 500 ms 29796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 24524 KB Output is correct
2 Correct 20 ms 24488 KB Output is correct
3 Correct 16 ms 24464 KB Output is correct
4 Correct 16 ms 24524 KB Output is correct
5 Correct 17 ms 24464 KB Output is correct
6 Correct 17 ms 24480 KB Output is correct
7 Correct 17 ms 24532 KB Output is correct
8 Correct 20 ms 24524 KB Output is correct
9 Correct 22 ms 24524 KB Output is correct
10 Correct 15 ms 24468 KB Output is correct
11 Correct 17 ms 24752 KB Output is correct
12 Correct 17 ms 24696 KB Output is correct
13 Correct 16 ms 24476 KB Output is correct
14 Correct 16 ms 24636 KB Output is correct
15 Correct 16 ms 24772 KB Output is correct
16 Correct 16 ms 24472 KB Output is correct
17 Correct 17 ms 24636 KB Output is correct
18 Correct 17 ms 24652 KB Output is correct
19 Correct 20 ms 24484 KB Output is correct
20 Correct 17 ms 24608 KB Output is correct
21 Correct 20 ms 24856 KB Output is correct
22 Correct 29 ms 25664 KB Output is correct
23 Correct 17 ms 24524 KB Output is correct
24 Correct 25 ms 25156 KB Output is correct
25 Correct 29 ms 25628 KB Output is correct
26 Correct 17 ms 24512 KB Output is correct
27 Correct 35 ms 25804 KB Output is correct
28 Correct 25 ms 24636 KB Output is correct
29 Correct 111 ms 26188 KB Output is correct
30 Correct 205 ms 27652 KB Output is correct
31 Correct 26 ms 24524 KB Output is correct
32 Correct 120 ms 26308 KB Output is correct
33 Correct 254 ms 27992 KB Output is correct
34 Correct 500 ms 29796 KB Output is correct
35 Correct 53 ms 24604 KB Output is correct
36 Execution timed out 1086 ms 28600 KB Time limit exceeded
37 Halted 0 ms 0 KB -