# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
897715 |
2024-01-03T15:31:38 Z |
denniskim |
NoM (RMI21_nom) |
C++17 |
|
235 ms |
94544 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())
ll n, m;
ll ss = 1000000007;
ll ans;
ll cou[2010];
ll dp[2010][2010];
struct NCK
{
ll fac[4000010] = {0, }, inv[4000010] = {0, };
ll power(ll xx, ll yy)
{
ll ret = 1;
while(yy > 0)
{
if(yy % 2)
ret = (ret * xx) % ss;
xx = (xx * xx) % ss;
yy /= 2;
}
return ret;
}
ll C(ll xx, ll yy)
{
if(xx < yy)
return 0;
if(xx == yy || !yy)
return 1;
long long r = (fac[xx] * inv[xx - yy]) % ss;
r = (r * inv[yy]) % ss;
return r;
}
void init(void)
{
fac[0] = 1;
fac[1] = 1;
for(ll i = 2 ; i <= 4000000 ; i++)
fac[i] = (fac[i - 1] * i) % ss;
inv[4000000] = power(fac[4000000], ss - 2);
for(ll i = 3999999 ; i >= 0 ; i--)
inv[i] = (inv[i + 1] * (i + 1)) % ss;
}
}nck;
int main(void)
{
fastio
cin >> n >> m;
nck.init();
ans = nck.fac[n * 2];
for(ll i = 1 ; i <= n * 2 ; i++)
{
ll gap = i % m;
if(gap == 0)
gap = m;
cou[gap]++;
}
for(ll i = 0 ; i <= m ; i++)
dp[0][i] = 1;
for(ll i = 1 ; i <= n ; i++)
{
for(ll j = 1 ; j <= m ; j++)
{
ll X = cou[j];
for(ll k = 1 ; k * 2 <= X && k <= i ; k++)
dp[i][j] = (dp[i][j] + dp[i - k][j - 1] * nck.C(X, k * 2) % ss * nck.fac[k * 2] % ss * nck.C(i, k) % ss) % ss;
}
for(ll j = 1 ; j <= m ; j++)
dp[i][j] = (dp[i][j] + dp[i][j - 1]) % ss;
}
for(ll i = 1 ; i <= n ; i++)
{
ll gap = dp[i][m] * nck.C(n, i) % ss * nck.fac[n * 2 - i * 2] % ss;
if(i & 1)
ans = (ans - gap) % ss;
else
ans = (ans + gap) % ss;
}
ans = (ans + ss) % ss;
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
64080 KB |
Output is correct |
2 |
Correct |
81 ms |
64208 KB |
Output is correct |
3 |
Correct |
82 ms |
64080 KB |
Output is correct |
4 |
Correct |
82 ms |
64080 KB |
Output is correct |
5 |
Correct |
82 ms |
64080 KB |
Output is correct |
6 |
Correct |
81 ms |
64184 KB |
Output is correct |
7 |
Correct |
82 ms |
64184 KB |
Output is correct |
8 |
Correct |
81 ms |
64216 KB |
Output is correct |
9 |
Correct |
81 ms |
64152 KB |
Output is correct |
10 |
Correct |
81 ms |
64152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
64080 KB |
Output is correct |
2 |
Correct |
81 ms |
64208 KB |
Output is correct |
3 |
Correct |
82 ms |
64080 KB |
Output is correct |
4 |
Correct |
82 ms |
64080 KB |
Output is correct |
5 |
Correct |
82 ms |
64080 KB |
Output is correct |
6 |
Correct |
81 ms |
64184 KB |
Output is correct |
7 |
Correct |
82 ms |
64184 KB |
Output is correct |
8 |
Correct |
81 ms |
64216 KB |
Output is correct |
9 |
Correct |
81 ms |
64152 KB |
Output is correct |
10 |
Correct |
81 ms |
64152 KB |
Output is correct |
11 |
Correct |
82 ms |
64336 KB |
Output is correct |
12 |
Correct |
82 ms |
64088 KB |
Output is correct |
13 |
Correct |
82 ms |
64084 KB |
Output is correct |
14 |
Correct |
82 ms |
64192 KB |
Output is correct |
15 |
Correct |
82 ms |
64136 KB |
Output is correct |
16 |
Correct |
81 ms |
64084 KB |
Output is correct |
17 |
Correct |
82 ms |
64148 KB |
Output is correct |
18 |
Correct |
82 ms |
64236 KB |
Output is correct |
19 |
Correct |
82 ms |
64168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
64080 KB |
Output is correct |
2 |
Correct |
81 ms |
64208 KB |
Output is correct |
3 |
Correct |
82 ms |
64080 KB |
Output is correct |
4 |
Correct |
82 ms |
64080 KB |
Output is correct |
5 |
Correct |
82 ms |
64080 KB |
Output is correct |
6 |
Correct |
81 ms |
64184 KB |
Output is correct |
7 |
Correct |
82 ms |
64184 KB |
Output is correct |
8 |
Correct |
81 ms |
64216 KB |
Output is correct |
9 |
Correct |
81 ms |
64152 KB |
Output is correct |
10 |
Correct |
81 ms |
64152 KB |
Output is correct |
11 |
Correct |
82 ms |
64336 KB |
Output is correct |
12 |
Correct |
82 ms |
64088 KB |
Output is correct |
13 |
Correct |
82 ms |
64084 KB |
Output is correct |
14 |
Correct |
82 ms |
64192 KB |
Output is correct |
15 |
Correct |
82 ms |
64136 KB |
Output is correct |
16 |
Correct |
81 ms |
64084 KB |
Output is correct |
17 |
Correct |
82 ms |
64148 KB |
Output is correct |
18 |
Correct |
82 ms |
64236 KB |
Output is correct |
19 |
Correct |
82 ms |
64168 KB |
Output is correct |
20 |
Correct |
83 ms |
64708 KB |
Output is correct |
21 |
Correct |
82 ms |
64452 KB |
Output is correct |
22 |
Correct |
85 ms |
65232 KB |
Output is correct |
23 |
Correct |
85 ms |
64912 KB |
Output is correct |
24 |
Correct |
86 ms |
65212 KB |
Output is correct |
25 |
Correct |
84 ms |
65108 KB |
Output is correct |
26 |
Correct |
87 ms |
64852 KB |
Output is correct |
27 |
Correct |
85 ms |
65428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
64080 KB |
Output is correct |
2 |
Correct |
81 ms |
64208 KB |
Output is correct |
3 |
Correct |
82 ms |
64080 KB |
Output is correct |
4 |
Correct |
82 ms |
64080 KB |
Output is correct |
5 |
Correct |
82 ms |
64080 KB |
Output is correct |
6 |
Correct |
81 ms |
64184 KB |
Output is correct |
7 |
Correct |
82 ms |
64184 KB |
Output is correct |
8 |
Correct |
81 ms |
64216 KB |
Output is correct |
9 |
Correct |
81 ms |
64152 KB |
Output is correct |
10 |
Correct |
81 ms |
64152 KB |
Output is correct |
11 |
Correct |
82 ms |
64336 KB |
Output is correct |
12 |
Correct |
82 ms |
64088 KB |
Output is correct |
13 |
Correct |
82 ms |
64084 KB |
Output is correct |
14 |
Correct |
82 ms |
64192 KB |
Output is correct |
15 |
Correct |
82 ms |
64136 KB |
Output is correct |
16 |
Correct |
81 ms |
64084 KB |
Output is correct |
17 |
Correct |
82 ms |
64148 KB |
Output is correct |
18 |
Correct |
82 ms |
64236 KB |
Output is correct |
19 |
Correct |
82 ms |
64168 KB |
Output is correct |
20 |
Correct |
83 ms |
64708 KB |
Output is correct |
21 |
Correct |
82 ms |
64452 KB |
Output is correct |
22 |
Correct |
85 ms |
65232 KB |
Output is correct |
23 |
Correct |
85 ms |
64912 KB |
Output is correct |
24 |
Correct |
86 ms |
65212 KB |
Output is correct |
25 |
Correct |
84 ms |
65108 KB |
Output is correct |
26 |
Correct |
87 ms |
64852 KB |
Output is correct |
27 |
Correct |
85 ms |
65428 KB |
Output is correct |
28 |
Correct |
103 ms |
66476 KB |
Output is correct |
29 |
Correct |
100 ms |
68028 KB |
Output is correct |
30 |
Correct |
98 ms |
69016 KB |
Output is correct |
31 |
Correct |
104 ms |
66500 KB |
Output is correct |
32 |
Correct |
102 ms |
68496 KB |
Output is correct |
33 |
Correct |
101 ms |
69800 KB |
Output is correct |
34 |
Correct |
114 ms |
73296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
64080 KB |
Output is correct |
2 |
Correct |
81 ms |
64208 KB |
Output is correct |
3 |
Correct |
82 ms |
64080 KB |
Output is correct |
4 |
Correct |
82 ms |
64080 KB |
Output is correct |
5 |
Correct |
82 ms |
64080 KB |
Output is correct |
6 |
Correct |
81 ms |
64184 KB |
Output is correct |
7 |
Correct |
82 ms |
64184 KB |
Output is correct |
8 |
Correct |
81 ms |
64216 KB |
Output is correct |
9 |
Correct |
81 ms |
64152 KB |
Output is correct |
10 |
Correct |
81 ms |
64152 KB |
Output is correct |
11 |
Correct |
82 ms |
64336 KB |
Output is correct |
12 |
Correct |
82 ms |
64088 KB |
Output is correct |
13 |
Correct |
82 ms |
64084 KB |
Output is correct |
14 |
Correct |
82 ms |
64192 KB |
Output is correct |
15 |
Correct |
82 ms |
64136 KB |
Output is correct |
16 |
Correct |
81 ms |
64084 KB |
Output is correct |
17 |
Correct |
82 ms |
64148 KB |
Output is correct |
18 |
Correct |
82 ms |
64236 KB |
Output is correct |
19 |
Correct |
82 ms |
64168 KB |
Output is correct |
20 |
Correct |
83 ms |
64708 KB |
Output is correct |
21 |
Correct |
82 ms |
64452 KB |
Output is correct |
22 |
Correct |
85 ms |
65232 KB |
Output is correct |
23 |
Correct |
85 ms |
64912 KB |
Output is correct |
24 |
Correct |
86 ms |
65212 KB |
Output is correct |
25 |
Correct |
84 ms |
65108 KB |
Output is correct |
26 |
Correct |
87 ms |
64852 KB |
Output is correct |
27 |
Correct |
85 ms |
65428 KB |
Output is correct |
28 |
Correct |
103 ms |
66476 KB |
Output is correct |
29 |
Correct |
100 ms |
68028 KB |
Output is correct |
30 |
Correct |
98 ms |
69016 KB |
Output is correct |
31 |
Correct |
104 ms |
66500 KB |
Output is correct |
32 |
Correct |
102 ms |
68496 KB |
Output is correct |
33 |
Correct |
101 ms |
69800 KB |
Output is correct |
34 |
Correct |
114 ms |
73296 KB |
Output is correct |
35 |
Correct |
228 ms |
70552 KB |
Output is correct |
36 |
Correct |
202 ms |
91020 KB |
Output is correct |
37 |
Correct |
225 ms |
70584 KB |
Output is correct |
38 |
Correct |
196 ms |
80464 KB |
Output is correct |
39 |
Correct |
178 ms |
87788 KB |
Output is correct |
40 |
Correct |
235 ms |
94544 KB |
Output is correct |