This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
long long n,m,d[2010][2010],r[2010],fact[4010],ans;
void factorial()
{
fact[0]=1;
for(int i=1;i<=4000;++i)
fact[i]=(fact[i-1]*i)%MOD;
}
long long putere(long long a,long long b)
{
if(b==0)
return 1;
long long m=putere(a,b/2);
m*=m;
m%=MOD;
if(b%2)
{
m*=a;
m%=MOD;
}
return m;
}
long long combinari(long long n,long long m)
{
long long ans=fact[n];
ans*=putere(fact[m],MOD-2);
ans%=MOD;
ans*=putere(fact[n-m],MOD-2);
ans%=MOD;
return ans;
}
long long aranjamente(long long n,long long m)
{
long long ans=fact[n];
ans*=putere(fact[n-m],MOD-2);
ans%=MOD;
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
factorial();
cin>>n>>m;
d[0][0]=1;
for(int i=1;i<=2*n;++i)
++r[i%m];
r[m]=r[0];
for(int j=0;j<=n;++j)
for(int i=1;i<=m;++i)
for(int k=0;2*k<=r[i]&&k<=j;++k)
{
d[i][j]+=combinari(j,k)*aranjamente(r[i],2*k)%MOD*d[i-1][j-k]%MOD;
if(d[i][j]>=MOD)
d[i][j]-=MOD;
}
for(int i=1;i<=n;++i)
{
ans+=((i-1)%2*2-1)*d[m][i]%MOD*fact[2*n-2*i]%MOD*combinari(n,i)%MOD;
if(ans>=MOD)
ans-=MOD;
if(ans<0)
ans+=MOD;
}
ans+=fact[2*n];
if(ans>=MOD)
ans-=MOD;
cout<<ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |