#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int M=1e9+7;
ll bin_pow(ll b, ll p=M-2) {
ll r=1;
for (; p; p/=2, b=b*b%M)
if (p%2)
r=r*b%M;
return r;
}
struct Mat {
int n, m;
vector<vector<int>> a;
Mat() {}
Mat(int n, int m) : n(n), m(m) {a.assign(n, vector<int>(m));}
vector<int>& operator[](int i) {return a[i];}
const vector<int>& operator[](int i) const {return a[i];}
Mat operator*(const Mat& b) const {
assert(m==b.n); Mat r(n, b.m);
for (int i=0; i<n; ++i) for (int j=0; j<m; ++j) for (int k=0; k<b.m; ++k) r[i][k]=(r[i][k]+(ll)a[i][j]*b[j][k])%M;
return r;
};
};
Mat mat_pow(Mat b, ll p) {
assert(b.n==b.m);
int n=b.n;
Mat r(n, n);
for (int i=0; i<n; ++i)
r[i][i]=1;
for (; p; p/=2, b=b*b)
if (p%2)
r=r*b;
return r;
}
int m, x, mask1[10], mask2[100];
ll n, k, C[11][11];
void init() {
mask1[0]=1<<1|1<<3;
mask1[1]=1<<1;
mask1[2]=1<<0|1<<3;
mask1[3]=1<<0|1<<1|1<<2;
mask1[4]=1<<1|1<<4;
mask1[5]=1<<0|1<<2|1<<4;
mask1[6]=1<<2|1<<3;
mask1[7]=1<<0|1<<1;
mask1[8]=1<<0|1<<2|1<<3|1<<4;
mask1[9]=1<<0|1<<1|1<<2|1<<4;
for (int i=0; i<100; ++i)
mask2[i]=(mask1[i/10]<<5)|mask1[i%10];
C[0][0]=1;
for (int i=1; i<=10; ++i)
for (int j=0; j<=i; ++j)
C[i][j]=((j?C[i-1][j-1]:0)+C[i-1][j])%M;
}
vector<int> get_changes(ll d) {
Mat a(1, 5*m+1), t(5*m+1, 5*m+1);
a[0][0]=1;
for (int i=0; i<=5*m; ++i) {
if (i)
t[i][i-1]=i;
if (i+1<=5*m)
t[i][i+1]=5*m-i;
}
a=a*mat_pow(t, d);
return a[0];
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
init();
cin >> m >> n >> k >> x;
int dim=m==1?10:100;
Mat a(1, dim), t(dim, dim);
a[0][x]=1;
vector<int> block_changes=get_changes(k);
for (int i=0; i<dim; ++i)
for (int j=0; j<dim; ++j) {
int num1=m==1?mask1[i]:mask2[i];
int num2=m==1?mask1[j]:mask2[j];
int dif=__builtin_popcount(num1^num2);
t[i][j]=(ll)block_changes[dif]*bin_pow(C[5*m][dif])%M;
}
a=a*mat_pow(t, n/k);
vector<int> final_changes=get_changes(n%k);
vector<ll> ans(dim);
for (int i=0; i<dim; ++i)
for (int j=0; j<dim; ++j) {
int num1=m==1?mask1[i]:mask2[i];
int num2=m==1?mask1[j]:mask2[j];
int dif=__builtin_popcount(num1^num2);
ans[j]=(ans[j]+(ll)a[0][i]*final_changes[dif]%M*bin_pow(C[5*m][dif]))%M;
}
for (int i=0; i<dim; ++i)
cout << ans[i] << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
280 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
280 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
500 KB |
Output is correct |
2 |
Correct |
9 ms |
468 KB |
Output is correct |
3 |
Correct |
10 ms |
500 KB |
Output is correct |
4 |
Correct |
9 ms |
456 KB |
Output is correct |
5 |
Correct |
10 ms |
504 KB |
Output is correct |
6 |
Correct |
8 ms |
452 KB |
Output is correct |
7 |
Correct |
8 ms |
468 KB |
Output is correct |
8 |
Correct |
8 ms |
456 KB |
Output is correct |
9 |
Correct |
8 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
460 KB |
Output is correct |
2 |
Correct |
89 ms |
488 KB |
Output is correct |
3 |
Correct |
136 ms |
500 KB |
Output is correct |
4 |
Correct |
207 ms |
492 KB |
Output is correct |
5 |
Correct |
166 ms |
480 KB |
Output is correct |
6 |
Correct |
153 ms |
484 KB |
Output is correct |
7 |
Correct |
176 ms |
488 KB |
Output is correct |
8 |
Correct |
193 ms |
468 KB |
Output is correct |
9 |
Correct |
157 ms |
492 KB |
Output is correct |
10 |
Correct |
158 ms |
484 KB |
Output is correct |
11 |
Correct |
23 ms |
484 KB |
Output is correct |
12 |
Correct |
11 ms |
468 KB |
Output is correct |
13 |
Correct |
166 ms |
484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
460 KB |
Output is correct |
2 |
Correct |
89 ms |
488 KB |
Output is correct |
3 |
Correct |
136 ms |
500 KB |
Output is correct |
4 |
Correct |
207 ms |
492 KB |
Output is correct |
5 |
Correct |
166 ms |
480 KB |
Output is correct |
6 |
Correct |
153 ms |
484 KB |
Output is correct |
7 |
Correct |
176 ms |
488 KB |
Output is correct |
8 |
Correct |
193 ms |
468 KB |
Output is correct |
9 |
Correct |
157 ms |
492 KB |
Output is correct |
10 |
Correct |
158 ms |
484 KB |
Output is correct |
11 |
Correct |
23 ms |
484 KB |
Output is correct |
12 |
Correct |
11 ms |
468 KB |
Output is correct |
13 |
Correct |
166 ms |
484 KB |
Output is correct |
14 |
Correct |
19 ms |
504 KB |
Output is correct |
15 |
Correct |
73 ms |
480 KB |
Output is correct |
16 |
Correct |
107 ms |
480 KB |
Output is correct |
17 |
Correct |
143 ms |
468 KB |
Output is correct |
18 |
Correct |
135 ms |
468 KB |
Output is correct |
19 |
Correct |
131 ms |
500 KB |
Output is correct |
20 |
Correct |
139 ms |
480 KB |
Output is correct |
21 |
Correct |
200 ms |
480 KB |
Output is correct |
22 |
Correct |
154 ms |
468 KB |
Output is correct |
23 |
Correct |
139 ms |
484 KB |
Output is correct |
24 |
Correct |
137 ms |
488 KB |
Output is correct |
25 |
Correct |
155 ms |
500 KB |
Output is correct |
26 |
Correct |
12 ms |
468 KB |
Output is correct |
27 |
Correct |
21 ms |
468 KB |
Output is correct |
28 |
Correct |
101 ms |
484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
500 KB |
Output is correct |
2 |
Correct |
9 ms |
468 KB |
Output is correct |
3 |
Correct |
10 ms |
500 KB |
Output is correct |
4 |
Correct |
9 ms |
456 KB |
Output is correct |
5 |
Correct |
10 ms |
504 KB |
Output is correct |
6 |
Correct |
8 ms |
452 KB |
Output is correct |
7 |
Correct |
8 ms |
468 KB |
Output is correct |
8 |
Correct |
8 ms |
456 KB |
Output is correct |
9 |
Correct |
8 ms |
468 KB |
Output is correct |
10 |
Correct |
34 ms |
460 KB |
Output is correct |
11 |
Correct |
89 ms |
488 KB |
Output is correct |
12 |
Correct |
136 ms |
500 KB |
Output is correct |
13 |
Correct |
207 ms |
492 KB |
Output is correct |
14 |
Correct |
166 ms |
480 KB |
Output is correct |
15 |
Correct |
153 ms |
484 KB |
Output is correct |
16 |
Correct |
176 ms |
488 KB |
Output is correct |
17 |
Correct |
193 ms |
468 KB |
Output is correct |
18 |
Correct |
157 ms |
492 KB |
Output is correct |
19 |
Correct |
158 ms |
484 KB |
Output is correct |
20 |
Correct |
23 ms |
484 KB |
Output is correct |
21 |
Correct |
11 ms |
468 KB |
Output is correct |
22 |
Correct |
166 ms |
484 KB |
Output is correct |
23 |
Correct |
19 ms |
504 KB |
Output is correct |
24 |
Correct |
73 ms |
480 KB |
Output is correct |
25 |
Correct |
107 ms |
480 KB |
Output is correct |
26 |
Correct |
143 ms |
468 KB |
Output is correct |
27 |
Correct |
135 ms |
468 KB |
Output is correct |
28 |
Correct |
131 ms |
500 KB |
Output is correct |
29 |
Correct |
139 ms |
480 KB |
Output is correct |
30 |
Correct |
200 ms |
480 KB |
Output is correct |
31 |
Correct |
154 ms |
468 KB |
Output is correct |
32 |
Correct |
139 ms |
484 KB |
Output is correct |
33 |
Correct |
137 ms |
488 KB |
Output is correct |
34 |
Correct |
155 ms |
500 KB |
Output is correct |
35 |
Correct |
12 ms |
468 KB |
Output is correct |
36 |
Correct |
21 ms |
468 KB |
Output is correct |
37 |
Correct |
101 ms |
484 KB |
Output is correct |
38 |
Correct |
10 ms |
468 KB |
Output is correct |
39 |
Correct |
8 ms |
468 KB |
Output is correct |
40 |
Correct |
8 ms |
468 KB |
Output is correct |
41 |
Correct |
9 ms |
468 KB |
Output is correct |
42 |
Correct |
9 ms |
452 KB |
Output is correct |
43 |
Correct |
9 ms |
632 KB |
Output is correct |
44 |
Correct |
11 ms |
468 KB |
Output is correct |
45 |
Correct |
166 ms |
468 KB |
Output is correct |
46 |
Correct |
160 ms |
496 KB |
Output is correct |
47 |
Correct |
11 ms |
500 KB |
Output is correct |
48 |
Correct |
8 ms |
500 KB |
Output is correct |
49 |
Correct |
9 ms |
468 KB |
Output is correct |
50 |
Correct |
8 ms |
468 KB |
Output is correct |
51 |
Correct |
8 ms |
468 KB |
Output is correct |
52 |
Correct |
54 ms |
488 KB |
Output is correct |