# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1068160 |
2024-08-21T08:08:36 Z |
정민찬(#11128) |
NoM (RMI21_nom) |
C++17 |
|
115 ms |
39768 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll mod = 1e9 + 7;
ll fastpow(ll a, ll b) {
ll ret = 1;
while (b) {
if (b % 2) ret = ret * a % mod;
a = a * a % mod;
b /= 2;
}
return ret;
}
ll fac[4010], inv[4010];
ll dp[4010][4010];
ll C(ll n, ll r) {
return fac[n] * inv[r] % mod * inv[n-r] % mod;
}
int main() {
ios_base :: sync_with_stdio(false); cin.tie(NULL);
fac[0] = 1;
for (ll i=1; i<=4000; i++) {
fac[i] = fac[i-1] * i % mod;
}
inv[4000] = fastpow(fac[4000], mod-2);
for (ll i=4000-1; i>=0; i--) {
inv[i] = inv[i+1] * (i+1) % mod;
}
ll N, M;
cin >> N >> M;
dp[0][0] = 1;
for (ll i=1; i<=M; i++) {
ll cnt = 2*N / M;
if (2*N % M >= i) cnt ++;
for (ll k=0; k<=cnt/2; k++) {
for (ll j=0; j<=N-k; j++) {
dp[i][j+k] += dp[i-1][j] * C(N-j, k) % mod * C(cnt, 2*k) % mod
* fac[2*k] % mod;
dp[i][j+k] %= mod;
}
}
}
ll ans = 0;
for (ll i=0; i<=N; i++) {
if (i % 2) {
ans -= dp[M][i] * fac[2*N-2*i] % mod;
ans = (ans + mod) % mod;
}
else {
ans += dp[M][i] * fac[2*N-2*i] % mod;
ans %= mod;
}
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
528 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
528 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
860 KB |
Output is correct |
22 |
Correct |
3 ms |
1884 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
2 ms |
1372 KB |
Output is correct |
25 |
Correct |
3 ms |
1884 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
4 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
528 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
860 KB |
Output is correct |
22 |
Correct |
3 ms |
1884 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
2 ms |
1372 KB |
Output is correct |
25 |
Correct |
3 ms |
1884 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
4 ms |
2396 KB |
Output is correct |
28 |
Correct |
5 ms |
600 KB |
Output is correct |
29 |
Correct |
10 ms |
3420 KB |
Output is correct |
30 |
Correct |
11 ms |
5724 KB |
Output is correct |
31 |
Correct |
5 ms |
632 KB |
Output is correct |
32 |
Correct |
10 ms |
3600 KB |
Output is correct |
33 |
Correct |
13 ms |
6492 KB |
Output is correct |
34 |
Correct |
24 ms |
10252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
528 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
860 KB |
Output is correct |
22 |
Correct |
3 ms |
1884 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
2 ms |
1372 KB |
Output is correct |
25 |
Correct |
3 ms |
1884 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
4 ms |
2396 KB |
Output is correct |
28 |
Correct |
5 ms |
600 KB |
Output is correct |
29 |
Correct |
10 ms |
3420 KB |
Output is correct |
30 |
Correct |
11 ms |
5724 KB |
Output is correct |
31 |
Correct |
5 ms |
632 KB |
Output is correct |
32 |
Correct |
10 ms |
3600 KB |
Output is correct |
33 |
Correct |
13 ms |
6492 KB |
Output is correct |
34 |
Correct |
24 ms |
10252 KB |
Output is correct |
35 |
Correct |
29 ms |
568 KB |
Output is correct |
36 |
Correct |
83 ms |
30544 KB |
Output is correct |
37 |
Correct |
29 ms |
600 KB |
Output is correct |
38 |
Correct |
60 ms |
14160 KB |
Output is correct |
39 |
Correct |
87 ms |
24916 KB |
Output is correct |
40 |
Correct |
115 ms |
39768 KB |
Output is correct |