Submission #786545

# Submission time Handle Problem Language Result Execution time Memory
786545 2023-07-18T09:01:04 Z 이성호(#10028) NoM (RMI21_nom) C++17
100 / 100
175 ms 109444 KB
#include <iostream>
#define int long long
using namespace std;
const int mod = 1e9 + 7;
int C[4005][4005];
int dp[2005][2005];
int cnt[2005];
int fac[4005] = {1};
int N, M;
signed main()
{
    cin >> N >> M;
    for (int i = 1; i <= 4000; i++) fac[i] = fac[i-1] * i % mod;
    for (int i = 0; i <= 4000; i++) {
        for (int j = 0; j <= i; j++) {
            if (j == 0 || j == i) C[i][j] = 1;
            else C[i][j] = (C[i-1][j-1] + C[i-1][j]) % mod;
        }
    }
    int q = (2*N) / M, r = (2*N) % M;
    for (int i = 1; i <= r; i++) cnt[i] = q + 1;
    for (int i = r + 1; i <= M; i++) cnt[i] = q;
    dp[0][0] = 1;
    for (int j = 1; j <= M; j++) {
        dp[0][j] = 1;
        for (int i = 1; i <= N; i++) {
            for (int k = 0; k <= cnt[j] / 2; k++) {
                dp[i][j] += (dp[i-k][j-1] * (C[cnt[j]][2*k] * fac[2*k] % mod) % mod) * C[i][k] % mod;
                dp[i][j] %= mod;
            }
        }
    }
    int ans = 0;
    for (int i = 0; i <= N; i++) {
        int tmp = (C[N][i] * dp[i][M] % mod) * fac[2*N-2*i] % mod;
        if (i % 2) ans -= tmp;
        else ans += tmp;
    }
    cout << (ans % mod + mod) % mod << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 38 ms 78092 KB Output is correct
2 Correct 39 ms 78096 KB Output is correct
3 Correct 38 ms 78052 KB Output is correct
4 Correct 41 ms 78060 KB Output is correct
5 Correct 40 ms 78088 KB Output is correct
6 Correct 39 ms 78028 KB Output is correct
7 Correct 41 ms 78092 KB Output is correct
8 Correct 38 ms 78032 KB Output is correct
9 Correct 38 ms 78052 KB Output is correct
10 Correct 42 ms 78120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 78092 KB Output is correct
2 Correct 39 ms 78096 KB Output is correct
3 Correct 38 ms 78052 KB Output is correct
4 Correct 41 ms 78060 KB Output is correct
5 Correct 40 ms 78088 KB Output is correct
6 Correct 39 ms 78028 KB Output is correct
7 Correct 41 ms 78092 KB Output is correct
8 Correct 38 ms 78032 KB Output is correct
9 Correct 38 ms 78052 KB Output is correct
10 Correct 42 ms 78120 KB Output is correct
11 Correct 37 ms 78472 KB Output is correct
12 Correct 39 ms 78292 KB Output is correct
13 Correct 39 ms 78384 KB Output is correct
14 Correct 38 ms 78336 KB Output is correct
15 Correct 39 ms 78368 KB Output is correct
16 Correct 42 ms 78412 KB Output is correct
17 Correct 41 ms 78384 KB Output is correct
18 Correct 38 ms 78316 KB Output is correct
19 Correct 38 ms 78340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 78092 KB Output is correct
2 Correct 39 ms 78096 KB Output is correct
3 Correct 38 ms 78052 KB Output is correct
4 Correct 41 ms 78060 KB Output is correct
5 Correct 40 ms 78088 KB Output is correct
6 Correct 39 ms 78028 KB Output is correct
7 Correct 41 ms 78092 KB Output is correct
8 Correct 38 ms 78032 KB Output is correct
9 Correct 38 ms 78052 KB Output is correct
10 Correct 42 ms 78120 KB Output is correct
11 Correct 37 ms 78472 KB Output is correct
12 Correct 39 ms 78292 KB Output is correct
13 Correct 39 ms 78384 KB Output is correct
14 Correct 38 ms 78336 KB Output is correct
15 Correct 39 ms 78368 KB Output is correct
16 Correct 42 ms 78412 KB Output is correct
17 Correct 41 ms 78384 KB Output is correct
18 Correct 38 ms 78316 KB Output is correct
19 Correct 38 ms 78340 KB Output is correct
20 Correct 43 ms 78788 KB Output is correct
21 Correct 39 ms 78844 KB Output is correct
22 Correct 40 ms 79644 KB Output is correct
23 Correct 40 ms 79112 KB Output is correct
24 Correct 40 ms 79564 KB Output is correct
25 Correct 42 ms 79580 KB Output is correct
26 Correct 40 ms 79080 KB Output is correct
27 Correct 40 ms 79948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 78092 KB Output is correct
2 Correct 39 ms 78096 KB Output is correct
3 Correct 38 ms 78052 KB Output is correct
4 Correct 41 ms 78060 KB Output is correct
5 Correct 40 ms 78088 KB Output is correct
6 Correct 39 ms 78028 KB Output is correct
7 Correct 41 ms 78092 KB Output is correct
8 Correct 38 ms 78032 KB Output is correct
9 Correct 38 ms 78052 KB Output is correct
10 Correct 42 ms 78120 KB Output is correct
11 Correct 37 ms 78472 KB Output is correct
12 Correct 39 ms 78292 KB Output is correct
13 Correct 39 ms 78384 KB Output is correct
14 Correct 38 ms 78336 KB Output is correct
15 Correct 39 ms 78368 KB Output is correct
16 Correct 42 ms 78412 KB Output is correct
17 Correct 41 ms 78384 KB Output is correct
18 Correct 38 ms 78316 KB Output is correct
19 Correct 38 ms 78340 KB Output is correct
20 Correct 43 ms 78788 KB Output is correct
21 Correct 39 ms 78844 KB Output is correct
22 Correct 40 ms 79644 KB Output is correct
23 Correct 40 ms 79112 KB Output is correct
24 Correct 40 ms 79564 KB Output is correct
25 Correct 42 ms 79580 KB Output is correct
26 Correct 40 ms 79080 KB Output is correct
27 Correct 40 ms 79948 KB Output is correct
28 Correct 44 ms 80708 KB Output is correct
29 Correct 46 ms 82392 KB Output is correct
30 Correct 46 ms 83608 KB Output is correct
31 Correct 42 ms 80692 KB Output is correct
32 Correct 47 ms 82608 KB Output is correct
33 Correct 52 ms 84488 KB Output is correct
34 Correct 59 ms 88044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 78092 KB Output is correct
2 Correct 39 ms 78096 KB Output is correct
3 Correct 38 ms 78052 KB Output is correct
4 Correct 41 ms 78060 KB Output is correct
5 Correct 40 ms 78088 KB Output is correct
6 Correct 39 ms 78028 KB Output is correct
7 Correct 41 ms 78092 KB Output is correct
8 Correct 38 ms 78032 KB Output is correct
9 Correct 38 ms 78052 KB Output is correct
10 Correct 42 ms 78120 KB Output is correct
11 Correct 37 ms 78472 KB Output is correct
12 Correct 39 ms 78292 KB Output is correct
13 Correct 39 ms 78384 KB Output is correct
14 Correct 38 ms 78336 KB Output is correct
15 Correct 39 ms 78368 KB Output is correct
16 Correct 42 ms 78412 KB Output is correct
17 Correct 41 ms 78384 KB Output is correct
18 Correct 38 ms 78316 KB Output is correct
19 Correct 38 ms 78340 KB Output is correct
20 Correct 43 ms 78788 KB Output is correct
21 Correct 39 ms 78844 KB Output is correct
22 Correct 40 ms 79644 KB Output is correct
23 Correct 40 ms 79112 KB Output is correct
24 Correct 40 ms 79564 KB Output is correct
25 Correct 42 ms 79580 KB Output is correct
26 Correct 40 ms 79080 KB Output is correct
27 Correct 40 ms 79948 KB Output is correct
28 Correct 44 ms 80708 KB Output is correct
29 Correct 46 ms 82392 KB Output is correct
30 Correct 46 ms 83608 KB Output is correct
31 Correct 42 ms 80692 KB Output is correct
32 Correct 47 ms 82608 KB Output is correct
33 Correct 52 ms 84488 KB Output is correct
34 Correct 59 ms 88044 KB Output is correct
35 Correct 69 ms 84908 KB Output is correct
36 Correct 145 ms 105992 KB Output is correct
37 Correct 60 ms 84696 KB Output is correct
38 Correct 97 ms 95208 KB Output is correct
39 Correct 117 ms 102832 KB Output is correct
40 Correct 175 ms 109444 KB Output is correct