#include<iostream>
#include<map>
using namespace std;
#define int long long
const long long MOD = 1e9+7;
int DIM;
struct matrix
{
int v[105][105];
};
matrix inm(matrix x, matrix y)
{
matrix aux;
for(int i=0;i<DIM;i++)
{
for(int j=0;j<DIM;j++)
{
aux.v[i][j]=0;
for(int k=0;k<DIM;k++)
{
aux.v[i][j] += 1LL*x.v[i][k] * y.v[k][j]%MOD;
aux.v[i][j]%=MOD;
}
}
}
return aux;
}
matrix unu;
matrix put(matrix a, int exp)
{
matrix aux=unu;
while(exp>0)
{
if(exp%2==1) aux = inm(aux,a);
a = inm(a,a);
exp/=2;
}
return aux;
}
int m;
map<pair<int,int>,pair<int,bool>> mp;
long long put_nr(long long a, int exp)
{
if(exp==0)
return 1;
if(exp%2==0)
return put_nr(a*a%MOD,exp/2);
else
return put_nr(a*a%MOD,exp/2)*a%MOD;
}
long long fact[3005],invf[3005];
long long comb(int x, int y)
{
if(x<y)
return 0;
return ((((fact[x]*invf[y])%MOD)*invf[x-y])%MOD);
}
matrix dp;
int calc(int cnt1, int k)
{
if(k%2!=cnt1%2)
return 0;
DIM=11;
for(int i=0;i<11;i++)
for(int j=0;j<11;j++)
dp.v[i][j]=0;
for(int cur=0;cur<=m*5;cur++)
{
if(cur>0) dp.v[cur][cur-1] = m*5-(cur-1);
if(cur<10) dp.v[cur][cur+1] = cur+1;
}
dp = put(dp,k);
DIM=100;
return dp.v[cnt1][0] * put_nr(comb(m*5,cnt1),MOD-2)%MOD;
}
int getmp(int config, int k)
{
int cnt1=0;
for(int i=0;i<10;i++)
if(((1<<i)&config))
cnt1++;
if(mp[{cnt1,k}].second==0)
{
mp[{cnt1,k}]={calc(cnt1,k),1};
}
return mp[{cnt1,k}].first;
}
int mask[100];
matrix calc_matrix(int k)
{
matrix aux;
for(int i=0;i<100;i++)
{
for(int j=0;j<100;j++)
{
if(m==1 && (i>9 || j>9)) aux.v[i][j]=0;
else aux.v[i][j] = getmp((mask[i]^mask[j]),k);
}
}
return aux;
}
void calc_mask()
{
mask[0] = (1<<1) + (1<<3);
mask[1] = (1<<1);
mask[2] = (1<<0) + (1<<3);
mask[3] = (1<<0) + (1<<1) + (1<<2);
mask[4] = (1<<1) + (1<<4);
mask[5] = (1<<0) + (1<<2) + (1<<4);
mask[6] = (1<<2) + (1<<3);
mask[7] = (1<<0) + (1<<1);
mask[8] = (1<<0) + (1<<2) + (1<<3) + (1<<4);
mask[9] = (1<<0) + (1<<1) + (1<<2) + (1<<4);
for(int i=10;i<100;i++)
{
mask[i] = (mask[i/10]<<5) + mask[i%10];
}
for(int i=9;i>=0;i--)
mask[i] += (mask[0]<<5);
}
signed main()
{
DIM=100;
for(int i=0;i<100;i++)
for(int j=0;j<100;j++)
unu.v[i][j]=0;
for(int i=0;i<100;i++)
unu.v[i][i]=1;
fact[0]=1;
for(int i=1;i<=3000;i++)
fact[i]=fact[i-1]*i%MOD;
invf[3000]=put_nr(fact[3000],MOD-2);
for(int i=2999;i>=0;i--)
invf[i]=invf[i+1]*(i+1)%MOD;
int n,k,x;
cin>>m>>n>>k>>x;
calc_mask();
matrix km = calc_matrix(k);
matrix rm = calc_matrix(n%k);
matrix rez=unu;
if(n/k > 0) rez = inm(rez,put(km,n/k));
if(n%k > 0) rez = inm(rez,rm);
for(int i=0;i<100;i++)
{
if(m==1 && i>9)
break;
cout<<rez.v[x][i]<<"\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
1624 KB |
Output is correct |
2 |
Correct |
21 ms |
1624 KB |
Output is correct |
3 |
Correct |
17 ms |
1688 KB |
Output is correct |
4 |
Correct |
13 ms |
1692 KB |
Output is correct |
5 |
Correct |
17 ms |
1628 KB |
Output is correct |
6 |
Correct |
13 ms |
1880 KB |
Output is correct |
7 |
Correct |
24 ms |
1688 KB |
Output is correct |
8 |
Correct |
28 ms |
1624 KB |
Output is correct |
9 |
Correct |
16 ms |
1628 KB |
Output is correct |
10 |
Correct |
24 ms |
1624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
1624 KB |
Output is correct |
2 |
Correct |
21 ms |
1624 KB |
Output is correct |
3 |
Correct |
17 ms |
1688 KB |
Output is correct |
4 |
Correct |
13 ms |
1692 KB |
Output is correct |
5 |
Correct |
17 ms |
1628 KB |
Output is correct |
6 |
Correct |
13 ms |
1880 KB |
Output is correct |
7 |
Correct |
24 ms |
1688 KB |
Output is correct |
8 |
Correct |
28 ms |
1624 KB |
Output is correct |
9 |
Correct |
16 ms |
1628 KB |
Output is correct |
10 |
Correct |
24 ms |
1624 KB |
Output is correct |
11 |
Correct |
21 ms |
1628 KB |
Output is correct |
12 |
Correct |
45 ms |
1628 KB |
Output is correct |
13 |
Correct |
27 ms |
1628 KB |
Output is correct |
14 |
Correct |
25 ms |
1628 KB |
Output is correct |
15 |
Correct |
21 ms |
1628 KB |
Output is correct |
16 |
Correct |
28 ms |
1624 KB |
Output is correct |
17 |
Correct |
24 ms |
1624 KB |
Output is correct |
18 |
Correct |
267 ms |
1624 KB |
Output is correct |
19 |
Correct |
272 ms |
1624 KB |
Output is correct |
20 |
Correct |
21 ms |
1628 KB |
Output is correct |
21 |
Correct |
19 ms |
1624 KB |
Output is correct |
22 |
Correct |
15 ms |
1692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
1712 KB |
Output is correct |
2 |
Correct |
14 ms |
1628 KB |
Output is correct |
3 |
Correct |
14 ms |
1624 KB |
Output is correct |
4 |
Correct |
14 ms |
1628 KB |
Output is correct |
5 |
Correct |
14 ms |
1684 KB |
Output is correct |
6 |
Correct |
14 ms |
1628 KB |
Output is correct |
7 |
Correct |
14 ms |
1628 KB |
Output is correct |
8 |
Correct |
14 ms |
1624 KB |
Output is correct |
9 |
Correct |
14 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
1664 KB |
Output is correct |
2 |
Correct |
148 ms |
1664 KB |
Output is correct |
3 |
Correct |
228 ms |
1684 KB |
Output is correct |
4 |
Correct |
292 ms |
1668 KB |
Output is correct |
5 |
Correct |
277 ms |
1872 KB |
Output is correct |
6 |
Correct |
264 ms |
1628 KB |
Output is correct |
7 |
Correct |
284 ms |
1628 KB |
Output is correct |
8 |
Correct |
267 ms |
1624 KB |
Output is correct |
9 |
Correct |
267 ms |
1628 KB |
Output is correct |
10 |
Correct |
270 ms |
1672 KB |
Output is correct |
11 |
Correct |
36 ms |
1628 KB |
Output is correct |
12 |
Correct |
17 ms |
1700 KB |
Output is correct |
13 |
Correct |
278 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
1664 KB |
Output is correct |
2 |
Correct |
148 ms |
1664 KB |
Output is correct |
3 |
Correct |
228 ms |
1684 KB |
Output is correct |
4 |
Correct |
292 ms |
1668 KB |
Output is correct |
5 |
Correct |
277 ms |
1872 KB |
Output is correct |
6 |
Correct |
264 ms |
1628 KB |
Output is correct |
7 |
Correct |
284 ms |
1628 KB |
Output is correct |
8 |
Correct |
267 ms |
1624 KB |
Output is correct |
9 |
Correct |
267 ms |
1628 KB |
Output is correct |
10 |
Correct |
270 ms |
1672 KB |
Output is correct |
11 |
Correct |
36 ms |
1628 KB |
Output is correct |
12 |
Correct |
17 ms |
1700 KB |
Output is correct |
13 |
Correct |
278 ms |
1628 KB |
Output is correct |
14 |
Correct |
37 ms |
1624 KB |
Output is correct |
15 |
Correct |
116 ms |
1672 KB |
Output is correct |
16 |
Correct |
172 ms |
1668 KB |
Output is correct |
17 |
Correct |
224 ms |
1628 KB |
Output is correct |
18 |
Correct |
243 ms |
1664 KB |
Output is correct |
19 |
Correct |
210 ms |
1672 KB |
Output is correct |
20 |
Correct |
244 ms |
1684 KB |
Output is correct |
21 |
Correct |
267 ms |
1624 KB |
Output is correct |
22 |
Correct |
274 ms |
1624 KB |
Output is correct |
23 |
Correct |
223 ms |
1664 KB |
Output is correct |
24 |
Correct |
234 ms |
1668 KB |
Output is correct |
25 |
Correct |
232 ms |
1872 KB |
Output is correct |
26 |
Correct |
25 ms |
1824 KB |
Output is correct |
27 |
Correct |
32 ms |
1628 KB |
Output is correct |
28 |
Correct |
175 ms |
1624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
1712 KB |
Output is correct |
2 |
Correct |
14 ms |
1628 KB |
Output is correct |
3 |
Correct |
14 ms |
1624 KB |
Output is correct |
4 |
Correct |
14 ms |
1628 KB |
Output is correct |
5 |
Correct |
14 ms |
1684 KB |
Output is correct |
6 |
Correct |
14 ms |
1628 KB |
Output is correct |
7 |
Correct |
14 ms |
1628 KB |
Output is correct |
8 |
Correct |
14 ms |
1624 KB |
Output is correct |
9 |
Correct |
14 ms |
1628 KB |
Output is correct |
10 |
Correct |
65 ms |
1664 KB |
Output is correct |
11 |
Correct |
148 ms |
1664 KB |
Output is correct |
12 |
Correct |
228 ms |
1684 KB |
Output is correct |
13 |
Correct |
292 ms |
1668 KB |
Output is correct |
14 |
Correct |
277 ms |
1872 KB |
Output is correct |
15 |
Correct |
264 ms |
1628 KB |
Output is correct |
16 |
Correct |
284 ms |
1628 KB |
Output is correct |
17 |
Correct |
267 ms |
1624 KB |
Output is correct |
18 |
Correct |
267 ms |
1628 KB |
Output is correct |
19 |
Correct |
270 ms |
1672 KB |
Output is correct |
20 |
Correct |
36 ms |
1628 KB |
Output is correct |
21 |
Correct |
17 ms |
1700 KB |
Output is correct |
22 |
Correct |
278 ms |
1628 KB |
Output is correct |
23 |
Correct |
37 ms |
1624 KB |
Output is correct |
24 |
Correct |
116 ms |
1672 KB |
Output is correct |
25 |
Correct |
172 ms |
1668 KB |
Output is correct |
26 |
Correct |
224 ms |
1628 KB |
Output is correct |
27 |
Correct |
243 ms |
1664 KB |
Output is correct |
28 |
Correct |
210 ms |
1672 KB |
Output is correct |
29 |
Correct |
244 ms |
1684 KB |
Output is correct |
30 |
Correct |
267 ms |
1624 KB |
Output is correct |
31 |
Correct |
274 ms |
1624 KB |
Output is correct |
32 |
Correct |
223 ms |
1664 KB |
Output is correct |
33 |
Correct |
234 ms |
1668 KB |
Output is correct |
34 |
Correct |
232 ms |
1872 KB |
Output is correct |
35 |
Correct |
25 ms |
1824 KB |
Output is correct |
36 |
Correct |
32 ms |
1628 KB |
Output is correct |
37 |
Correct |
175 ms |
1624 KB |
Output is correct |
38 |
Correct |
23 ms |
1628 KB |
Output is correct |
39 |
Correct |
23 ms |
1624 KB |
Output is correct |
40 |
Correct |
24 ms |
1628 KB |
Output is correct |
41 |
Correct |
24 ms |
1624 KB |
Output is correct |
42 |
Correct |
25 ms |
1624 KB |
Output is correct |
43 |
Correct |
26 ms |
1516 KB |
Output is correct |
44 |
Correct |
25 ms |
1880 KB |
Output is correct |
45 |
Correct |
266 ms |
1624 KB |
Output is correct |
46 |
Correct |
260 ms |
1628 KB |
Output is correct |
47 |
Correct |
28 ms |
1628 KB |
Output is correct |
48 |
Correct |
24 ms |
1628 KB |
Output is correct |
49 |
Correct |
17 ms |
1628 KB |
Output is correct |
50 |
Correct |
14 ms |
1628 KB |
Output is correct |
51 |
Correct |
18 ms |
1628 KB |
Output is correct |
52 |
Correct |
95 ms |
1672 KB |
Output is correct |