# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
646029 |
2022-09-28T14:01:48 Z |
Kripton |
NoM (RMI21_nom) |
C++14 |
|
62 ms |
364 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast","unroll-loops")
using namespace std;
const int MOD=1e9+7;
int lgput(int a,int b)
{
int rez=1;
while(b)
{
if(b%2)
rez=1LL*rez*a%MOD;
a=1LL*a*a%MOD;
b/=2;
}
return rez;
}
template <const int MOD> struct numar{
int x;
numar(int x=0){
this->x=x;
}
bool operator!=(const numar &other) const{
return x!=other.x;
}
numar& operator=(const numar &other){
x=other.x;
return *this;
}
numar operator+(const numar &other) const{
return numar(x+other.x>=MOD?x+other.x-MOD:x+other.x);
}
numar operator-(const numar &other) const{
return numar(x-other.x<0?x-other.x+MOD:x-other.x);
}
numar operator*(const numar &other) const{
return numar(1LL*x*other.x%MOD);
}
numar operator/(const numar &other) const{
return numar(1LL*x*lgput(other.x,MOD-2)%MOD);
}
void afis(){
cout<<x;
}
};
numar <MOD> fact[4001],invfact[4001];
numar <MOD> dp[2][2001];
int exist[2],exidr[2];
numar <MOD> comb(int a,int b)
{
if(b>a)
return 0;
return fact[a]*invfact[b]*invfact[a-b];
}
numar <MOD> put[4001];
int main()
{
int n,m,i,j,l;
cin>>n>>m;
fact[0]=1;
put[0]=1;
for(i=1;i<=2*n;i++)
put[i]=put[i-1]*2;
for(i=1;i<=2*n;i++)
fact[i]=fact[i-1]*i;
invfact[2*n]=lgput(fact[2*n].x,MOD-2);
for(i=2*n-1;i>=0;i--)
invfact[i]=invfact[i+1]*(i+1);
int cnt2=2*n%m;//2*n/m+1
int cnt1=m-cnt2;//2*n/m;
int k=2*n/m;
int sum=k;
dp[1][n-k]=comb(n,k)*put[k]*fact[k];
exist[1]=n-k;
exidr[1]=n-k;
for(i=1;i<=cnt1-1;i++)
{
for(j=0;j<=n;j++)
dp[1-(i&1)][j]=0;
exist[1-(i&1)]=n+1;
exidr[1-(i&1)]=-1;
for(j=exist[i&1];j<=exidr[i&1];j++)
if(dp[i&1][j]!=0)
{
int unu=(n-j)*2-sum;
if(unu<0)
break;
for(l=max(j-k,0);l<=j;l++)
{
if(k-(j-l)>unu)
break;
dp[1-(i&1)][l]=dp[1-(i&1)][l]+dp[i&1][j]*fact[k]*comb(j,j-l)*put[j-l]*comb(unu,k-(j-l));
exist[1-(i&1)]=min(exist[1-(i&1)],l);
exidr[1-(i&1)]=max(exidr[1-(i&1)],l);
}
}
sum+=k;
}
k++;
for(;i<=cnt1+cnt2-1;i++)
{
for(j=0;j<=n;j++)
dp[1-(i&1)][j]=0;
exist[1-(i&1)]=n+1;
exidr[1-(i&1)]=-1;
for(j=exist[i&1];j<=exidr[i&1];j++)
if(dp[i&1][j]!=0)
{
int unu=(n-j)*2-sum;
if(unu<0)
break;
for(l=max(j-k,0);l<=j;l++)
{
if(k-(j-l)>unu)
break;
dp[1-(i&1)][l]=dp[1-(i&1)][l]+dp[i&1][j]*fact[k]*comb(j,j-l)*put[j-l]*comb(unu,k-(j-l));
exist[1-(i&1)]=min(exist[1-(i&1)],l);
exidr[1-(i&1)]=max(exidr[1-(i&1)],l);
}
}
sum+=k;
}
dp[m%2][0].afis();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
3 ms |
340 KB |
Output is correct |
29 |
Correct |
8 ms |
340 KB |
Output is correct |
30 |
Correct |
8 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
340 KB |
Output is correct |
32 |
Correct |
6 ms |
360 KB |
Output is correct |
33 |
Correct |
9 ms |
340 KB |
Output is correct |
34 |
Correct |
13 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
3 ms |
340 KB |
Output is correct |
29 |
Correct |
8 ms |
340 KB |
Output is correct |
30 |
Correct |
8 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
340 KB |
Output is correct |
32 |
Correct |
6 ms |
360 KB |
Output is correct |
33 |
Correct |
9 ms |
340 KB |
Output is correct |
34 |
Correct |
13 ms |
364 KB |
Output is correct |
35 |
Correct |
21 ms |
340 KB |
Output is correct |
36 |
Correct |
51 ms |
340 KB |
Output is correct |
37 |
Correct |
21 ms |
340 KB |
Output is correct |
38 |
Correct |
34 ms |
340 KB |
Output is correct |
39 |
Correct |
39 ms |
364 KB |
Output is correct |
40 |
Correct |
62 ms |
352 KB |
Output is correct |