#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
/*ifstream fin("num.in");
ofstream fout("num.out");*/
typedef long long ll;
const ll mod=1e9+7;
ll n,m,dp[2005][2005],ans,fact[10005],invfact[10005],nr[10005];
ll pw(ll a, ll b)
{
ll rez=1;
while(b)
{
if(b&1)
rez=(rez*a)%mod;
b/=2;
a=(a*a)%mod;
}
return rez;
}
ll inv(ll a)
{
return pw(a,mod-2);
}
ll comb(ll a, ll b)
{
if(a<b)
return 0;
ll rez=(fact[a]*invfact[b])%mod;
rez=(rez*invfact[a-b])%mod;
return rez;
}
ll aranj(ll a, ll b)
{
ll rez=comb(a,b);
rez=(rez*fact[b])%mod;
return rez;
}
int main()
{
fact[0]=invfact[0]=1;
for(ll i=1;i<=10000;i++)
{
fact[i]=(fact[i-1]*i)%mod;
invfact[i]=inv(fact[i])%mod;
}
cin>>n>>m;
for(int i=1;i<=2*n;i++)
nr[i%m+1]++;
dp[0][0]=1;
int suma=0;
for(int i=1;i<=m;i++)
{
suma+=nr[i];
for(int cur=0;cur<=nr[i]/2;cur++)
{
ll x=aranj(nr[i],cur*2);
for(int tot=cur;tot<=suma/2;tot++)
{
ll val=dp[i-1][tot-cur];
val=(val*x)%mod;
val=(val*comb(n-tot+cur,cur))%mod;
dp[i][tot]=(dp[i][tot]+val)%mod;
}
}
//cout<<dp[i][0]<<' ';
}
for(int i=0;i<=n;i++)
{
ll val=dp[m][i]%mod;
val=(val*fact[2*n-2*i])%mod;
if(i%2==1)
{
ans-=val;
if(ans<0)
ans+=mod;
}
else
ans=(ans+val)%mod;
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
2 ms |
584 KB |
Output is correct |
12 |
Correct |
2 ms |
588 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
588 KB |
Output is correct |
15 |
Correct |
2 ms |
720 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
17 |
Correct |
2 ms |
588 KB |
Output is correct |
18 |
Correct |
2 ms |
588 KB |
Output is correct |
19 |
Correct |
2 ms |
464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
2 ms |
584 KB |
Output is correct |
12 |
Correct |
2 ms |
588 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
588 KB |
Output is correct |
15 |
Correct |
2 ms |
720 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
17 |
Correct |
2 ms |
588 KB |
Output is correct |
18 |
Correct |
2 ms |
588 KB |
Output is correct |
19 |
Correct |
2 ms |
464 KB |
Output is correct |
20 |
Correct |
2 ms |
460 KB |
Output is correct |
21 |
Correct |
2 ms |
716 KB |
Output is correct |
22 |
Correct |
4 ms |
1740 KB |
Output is correct |
23 |
Correct |
2 ms |
460 KB |
Output is correct |
24 |
Correct |
3 ms |
1100 KB |
Output is correct |
25 |
Correct |
4 ms |
1624 KB |
Output is correct |
26 |
Correct |
2 ms |
460 KB |
Output is correct |
27 |
Correct |
3 ms |
2000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
2 ms |
584 KB |
Output is correct |
12 |
Correct |
2 ms |
588 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
588 KB |
Output is correct |
15 |
Correct |
2 ms |
720 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
17 |
Correct |
2 ms |
588 KB |
Output is correct |
18 |
Correct |
2 ms |
588 KB |
Output is correct |
19 |
Correct |
2 ms |
464 KB |
Output is correct |
20 |
Correct |
2 ms |
460 KB |
Output is correct |
21 |
Correct |
2 ms |
716 KB |
Output is correct |
22 |
Correct |
4 ms |
1740 KB |
Output is correct |
23 |
Correct |
2 ms |
460 KB |
Output is correct |
24 |
Correct |
3 ms |
1100 KB |
Output is correct |
25 |
Correct |
4 ms |
1624 KB |
Output is correct |
26 |
Correct |
2 ms |
460 KB |
Output is correct |
27 |
Correct |
3 ms |
2000 KB |
Output is correct |
28 |
Correct |
3 ms |
452 KB |
Output is correct |
29 |
Correct |
6 ms |
2636 KB |
Output is correct |
30 |
Correct |
8 ms |
4300 KB |
Output is correct |
31 |
Correct |
4 ms |
588 KB |
Output is correct |
32 |
Correct |
6 ms |
2764 KB |
Output is correct |
33 |
Correct |
9 ms |
4940 KB |
Output is correct |
34 |
Correct |
13 ms |
7168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
2 ms |
584 KB |
Output is correct |
12 |
Correct |
2 ms |
588 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
588 KB |
Output is correct |
15 |
Correct |
2 ms |
720 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
17 |
Correct |
2 ms |
588 KB |
Output is correct |
18 |
Correct |
2 ms |
588 KB |
Output is correct |
19 |
Correct |
2 ms |
464 KB |
Output is correct |
20 |
Correct |
2 ms |
460 KB |
Output is correct |
21 |
Correct |
2 ms |
716 KB |
Output is correct |
22 |
Correct |
4 ms |
1740 KB |
Output is correct |
23 |
Correct |
2 ms |
460 KB |
Output is correct |
24 |
Correct |
3 ms |
1100 KB |
Output is correct |
25 |
Correct |
4 ms |
1624 KB |
Output is correct |
26 |
Correct |
2 ms |
460 KB |
Output is correct |
27 |
Correct |
3 ms |
2000 KB |
Output is correct |
28 |
Correct |
3 ms |
452 KB |
Output is correct |
29 |
Correct |
6 ms |
2636 KB |
Output is correct |
30 |
Correct |
8 ms |
4300 KB |
Output is correct |
31 |
Correct |
4 ms |
588 KB |
Output is correct |
32 |
Correct |
6 ms |
2764 KB |
Output is correct |
33 |
Correct |
9 ms |
4940 KB |
Output is correct |
34 |
Correct |
13 ms |
7168 KB |
Output is correct |
35 |
Correct |
13 ms |
592 KB |
Output is correct |
36 |
Correct |
39 ms |
19140 KB |
Output is correct |
37 |
Correct |
13 ms |
584 KB |
Output is correct |
38 |
Correct |
25 ms |
9024 KB |
Output is correct |
39 |
Correct |
31 ms |
16128 KB |
Output is correct |
40 |
Correct |
48 ms |
23208 KB |
Output is correct |