This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//https://www.instagram.com/_modwwe/
#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".ans","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
void phongbeo();
const ll inf=1e18;
const int mod2=1e9+7;
const int mod1=998244353;
struct icd
{
long double a;
int b;
};
struct ib
{
ll a;
ll b;
};
struct ic
{
int a,b,c;
};
struct id
{
int a,b,c,d;
};
struct ie
{
int a,b,c,d,e;
};
ll n,m,s1,s2,s4,s3,sf,k,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,s33,dem3,l,r,mid;
int i,s10,s12;
int kk;
int el=29;
main()
{
#ifndef ONLINE_JUDGE
// fin(task),fou(task);
#endif
NHP
/// cin>>s1;
// modwwe
phongbeo();
}
int dp[2002][2001];
int fac[4001];
int c[2001];
int invf[4001];
int ipow(int x, int p)
{
int ret = 1, piv = x;
while(p)
{
if(p&1) ret *= piv;
piv *= piv;
ret %= mod2;
piv %= mod2;
p >>= 1;
}
return ret;
}
int add(int x,int y)
{
if(x+y>=mod2) x-=mod2;
return x+y;
}
int C(int x,int y)
{
return fac[x]*(invf[x-y]*invf[y]%mod2)%mod2;
}
void phongbeo()
{
cin>>n>>m;
for(int i=1;i<=n*2;i++)
c[i%m+1]++;
fac[0]=1;
invf[0]=1;
for(int i=1;i<=n*2;i++)
fac[i]=(fac[i-1]*i)%mod2,
invf[i]=ipow(fac[i],mod2-2);
dp[1][0]=1;
s7=1;
for(int i=1;i<=n;i++)
s7=(s7*2)%mod2;
for(int i=1;i<=m;i++)
{
for(int f=0;f<=c[i];f++)
{
s2=c[i]-f;
s6=n*2-s5;
for(int j=s2;j<=n;j++){
if(dp[i][j]&&(s6-j)/2>=f&&j-s2+f<=n)
dp[i+1][j-s2+f]=add(dp[i+1][j-s2+f],(dp[i][j]*C(j,s2)%mod2)*C((s6-j)/2,f)%mod2);
}
}
s5+=c[i];
s7=(s7*fac[c[i]])%mod2;
}
cout<<(s7*dp[m+1][0])%mod2;
}
Compilation message (stderr)
Main.cpp:51:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
51 | main()
| ^~~~
Main.cpp: In function 'void phongbeo()':
Main.cpp:90:7: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
90 | for(int i=1;i<=n*2;i++)
| ^~~
Main.cpp:92:10: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
92 | fac[0]=1;
| ^~~
# | 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... |