#include <bits/stdc++.h>
using namespace std;
#ifndef _LOCAL
//#pragma GCC optimize("O3,Ofast")
#else
#pragma GCC optimize("O0")
#endif
template<typename t> inline void umin(t &a, const t b) {a = min(a, b);}
template<typename t> inline void umax(t &a, const t b) {a = max(a, b);}
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
typedef int8_t byte;
ll time() {return chrono::system_clock().now().time_since_epoch().count();}
mt19937 rnd(time());
#define ft first
#define sd second
#define len(f) int((f).size())
#define bnd(f) (f).begin(), (f).end()
#define _ <<' '<<
#define pc __builtin_popcount
#define int ll
const int inf = 1e9 + 5;
const ll inf64 = 4e18 + 5;
const int md = 1e9 + 7;
namespace MD {
void add(int &a, const int b) {if((a += b) >= md) a -= md;}
void sub(int &a, const int b) {if((a -= b) < 0) a += md;}
int prod(const int a, const int b) {return ll(a) * b % md;}
};
int m, x;
ll n, k;
const string I[10] = {
" # # ",
" # ",
"# # ",
"### ",
" # #",
"# # #",
" ## ",
"## ",
"# ###",
"### #"
};
int ms[10];
int dif[10][10];
const int N = 11;
const int M = 100;
template<int n> struct mat {
int f[n][n];
mat operator* (const mat &o) const {
mat res;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j) {
res.f[i][j] = 0;
for(int t = 0; t < n; ++t)
MD::add(res.f[i][j], MD::prod(f[i][t], o.f[t][j]));
}
}
return res;
}
void e() {
memset(f, 0, sizeof f);
for(int i = 0; i < n; ++i)
f[i][i] = 1;
}
void c() {
memset(f, 0, sizeof f);
}
};
template<int n> mat<n> power(mat<n> f, ll p) {
mat<n> res;
res.e();
for(ll i = 1; p; i <<= 1) {
if(i > 1) f = f * f;
if(i & p)
res = res * f,
p ^= i;
}
return res;
}
mat<M> make(ll n) {
mat<N> a;
a.c();
for(int i = 0, p = m * 5; p; --p, ++i) {
int j = i + 1;
a.f[i][j] += j;
a.f[j][i] += p;
}
a = power(a, n);
mat<M> res;
res.c();
if(m == 2) {
for(int i = 0, fi = 0; i < 10; ++i)
for(int j = 0; j < 10; ++j, ++fi)
for(int x = 0, se = 0; x < 10; ++x)
for(int y = 0; y < 10; ++y, ++se)
res.f[fi][se] = a.f[0][dif[i][x] + dif[j][y]];
} else {
for(int i = 0; i < 10; ++i)
for(int j = 0; j < 10; ++j)
res.f[i][j] = a.f[0][dif[i][j]];
}
return res;
}
void solve() {
for(int i = 0; i < 10; ++i)
for(int j = 0; j < 5; ++j)
if(I[i][j] == '#') ms[i] |= 1 << j;
for(int i = 0; i < 10; ++i)
for(int j = 0; j < 10; ++j)
dif[i][j] = pc(ms[i] ^ ms[j]);
cin >> m >> n >> k >> x;
mat<M> a = power(make(k), n / k);
if(n % k) a = make(n % k) * a;
int u = m == 1 ? 10 : 100;
for(int i = 0; i < u; ++i)
cout << a.f[i][x] << '\n';
#ifdef KEK
cerr << endl;
#endif // KEK
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifndef _LOCAL
// freopen("file.in", "r", stdin);
// freopen("file.out", "w", stdout);
#else
system("color a");
freopen("in.txt", "r", stdin);
int t; cin >> t;
while(t--)
#endif
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
620 KB |
Output is correct |
2 |
Correct |
10 ms |
620 KB |
Output is correct |
3 |
Correct |
7 ms |
748 KB |
Output is correct |
4 |
Correct |
4 ms |
620 KB |
Output is correct |
5 |
Correct |
9 ms |
748 KB |
Output is correct |
6 |
Correct |
4 ms |
620 KB |
Output is correct |
7 |
Correct |
13 ms |
748 KB |
Output is correct |
8 |
Correct |
15 ms |
620 KB |
Output is correct |
9 |
Correct |
7 ms |
748 KB |
Output is correct |
10 |
Correct |
12 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
620 KB |
Output is correct |
2 |
Correct |
10 ms |
620 KB |
Output is correct |
3 |
Correct |
7 ms |
748 KB |
Output is correct |
4 |
Correct |
4 ms |
620 KB |
Output is correct |
5 |
Correct |
9 ms |
748 KB |
Output is correct |
6 |
Correct |
4 ms |
620 KB |
Output is correct |
7 |
Correct |
13 ms |
748 KB |
Output is correct |
8 |
Correct |
15 ms |
620 KB |
Output is correct |
9 |
Correct |
7 ms |
748 KB |
Output is correct |
10 |
Correct |
12 ms |
620 KB |
Output is correct |
11 |
Correct |
10 ms |
748 KB |
Output is correct |
12 |
Correct |
27 ms |
748 KB |
Output is correct |
13 |
Correct |
13 ms |
748 KB |
Output is correct |
14 |
Correct |
13 ms |
848 KB |
Output is correct |
15 |
Correct |
7 ms |
748 KB |
Output is correct |
16 |
Correct |
13 ms |
748 KB |
Output is correct |
17 |
Correct |
10 ms |
748 KB |
Output is correct |
18 |
Correct |
206 ms |
620 KB |
Output is correct |
19 |
Correct |
216 ms |
876 KB |
Output is correct |
20 |
Correct |
8 ms |
748 KB |
Output is correct |
21 |
Correct |
7 ms |
748 KB |
Output is correct |
22 |
Correct |
7 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
620 KB |
Output is correct |
2 |
Correct |
4 ms |
620 KB |
Output is correct |
3 |
Correct |
4 ms |
620 KB |
Output is correct |
4 |
Correct |
5 ms |
620 KB |
Output is correct |
5 |
Correct |
4 ms |
620 KB |
Output is correct |
6 |
Correct |
4 ms |
620 KB |
Output is correct |
7 |
Correct |
4 ms |
620 KB |
Output is correct |
8 |
Correct |
4 ms |
640 KB |
Output is correct |
9 |
Correct |
4 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
848 KB |
Output is correct |
2 |
Correct |
106 ms |
620 KB |
Output is correct |
3 |
Correct |
167 ms |
748 KB |
Output is correct |
4 |
Correct |
220 ms |
876 KB |
Output is correct |
5 |
Correct |
201 ms |
748 KB |
Output is correct |
6 |
Correct |
192 ms |
852 KB |
Output is correct |
7 |
Correct |
209 ms |
852 KB |
Output is correct |
8 |
Correct |
228 ms |
620 KB |
Output is correct |
9 |
Correct |
196 ms |
748 KB |
Output is correct |
10 |
Correct |
193 ms |
748 KB |
Output is correct |
11 |
Correct |
21 ms |
620 KB |
Output is correct |
12 |
Correct |
7 ms |
620 KB |
Output is correct |
13 |
Correct |
213 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
848 KB |
Output is correct |
2 |
Correct |
106 ms |
620 KB |
Output is correct |
3 |
Correct |
167 ms |
748 KB |
Output is correct |
4 |
Correct |
220 ms |
876 KB |
Output is correct |
5 |
Correct |
201 ms |
748 KB |
Output is correct |
6 |
Correct |
192 ms |
852 KB |
Output is correct |
7 |
Correct |
209 ms |
852 KB |
Output is correct |
8 |
Correct |
228 ms |
620 KB |
Output is correct |
9 |
Correct |
196 ms |
748 KB |
Output is correct |
10 |
Correct |
193 ms |
748 KB |
Output is correct |
11 |
Correct |
21 ms |
620 KB |
Output is correct |
12 |
Correct |
7 ms |
620 KB |
Output is correct |
13 |
Correct |
213 ms |
852 KB |
Output is correct |
14 |
Correct |
21 ms |
748 KB |
Output is correct |
15 |
Correct |
80 ms |
748 KB |
Output is correct |
16 |
Correct |
124 ms |
852 KB |
Output is correct |
17 |
Correct |
208 ms |
748 KB |
Output is correct |
18 |
Correct |
175 ms |
748 KB |
Output is correct |
19 |
Correct |
153 ms |
876 KB |
Output is correct |
20 |
Correct |
176 ms |
748 KB |
Output is correct |
21 |
Correct |
199 ms |
748 KB |
Output is correct |
22 |
Correct |
201 ms |
748 KB |
Output is correct |
23 |
Correct |
165 ms |
876 KB |
Output is correct |
24 |
Correct |
183 ms |
748 KB |
Output is correct |
25 |
Correct |
174 ms |
748 KB |
Output is correct |
26 |
Correct |
13 ms |
748 KB |
Output is correct |
27 |
Correct |
21 ms |
876 KB |
Output is correct |
28 |
Correct |
127 ms |
876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
620 KB |
Output is correct |
2 |
Correct |
4 ms |
620 KB |
Output is correct |
3 |
Correct |
4 ms |
620 KB |
Output is correct |
4 |
Correct |
5 ms |
620 KB |
Output is correct |
5 |
Correct |
4 ms |
620 KB |
Output is correct |
6 |
Correct |
4 ms |
620 KB |
Output is correct |
7 |
Correct |
4 ms |
620 KB |
Output is correct |
8 |
Correct |
4 ms |
640 KB |
Output is correct |
9 |
Correct |
4 ms |
620 KB |
Output is correct |
10 |
Correct |
42 ms |
848 KB |
Output is correct |
11 |
Correct |
106 ms |
620 KB |
Output is correct |
12 |
Correct |
167 ms |
748 KB |
Output is correct |
13 |
Correct |
220 ms |
876 KB |
Output is correct |
14 |
Correct |
201 ms |
748 KB |
Output is correct |
15 |
Correct |
192 ms |
852 KB |
Output is correct |
16 |
Correct |
209 ms |
852 KB |
Output is correct |
17 |
Correct |
228 ms |
620 KB |
Output is correct |
18 |
Correct |
196 ms |
748 KB |
Output is correct |
19 |
Correct |
193 ms |
748 KB |
Output is correct |
20 |
Correct |
21 ms |
620 KB |
Output is correct |
21 |
Correct |
7 ms |
620 KB |
Output is correct |
22 |
Correct |
213 ms |
852 KB |
Output is correct |
23 |
Correct |
21 ms |
748 KB |
Output is correct |
24 |
Correct |
80 ms |
748 KB |
Output is correct |
25 |
Correct |
124 ms |
852 KB |
Output is correct |
26 |
Correct |
208 ms |
748 KB |
Output is correct |
27 |
Correct |
175 ms |
748 KB |
Output is correct |
28 |
Correct |
153 ms |
876 KB |
Output is correct |
29 |
Correct |
176 ms |
748 KB |
Output is correct |
30 |
Correct |
199 ms |
748 KB |
Output is correct |
31 |
Correct |
201 ms |
748 KB |
Output is correct |
32 |
Correct |
165 ms |
876 KB |
Output is correct |
33 |
Correct |
183 ms |
748 KB |
Output is correct |
34 |
Correct |
174 ms |
748 KB |
Output is correct |
35 |
Correct |
13 ms |
748 KB |
Output is correct |
36 |
Correct |
21 ms |
876 KB |
Output is correct |
37 |
Correct |
127 ms |
876 KB |
Output is correct |
38 |
Correct |
10 ms |
788 KB |
Output is correct |
39 |
Correct |
7 ms |
748 KB |
Output is correct |
40 |
Correct |
7 ms |
748 KB |
Output is correct |
41 |
Correct |
8 ms |
748 KB |
Output is correct |
42 |
Correct |
10 ms |
748 KB |
Output is correct |
43 |
Correct |
8 ms |
876 KB |
Output is correct |
44 |
Correct |
7 ms |
748 KB |
Output is correct |
45 |
Correct |
195 ms |
620 KB |
Output is correct |
46 |
Correct |
195 ms |
620 KB |
Output is correct |
47 |
Correct |
10 ms |
748 KB |
Output is correct |
48 |
Correct |
7 ms |
748 KB |
Output is correct |
49 |
Correct |
4 ms |
620 KB |
Output is correct |
50 |
Correct |
4 ms |
620 KB |
Output is correct |
51 |
Correct |
7 ms |
876 KB |
Output is correct |
52 |
Correct |
61 ms |
748 KB |
Output is correct |