#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<long long, long long>
#define plll pair<long long, pll>
#define tiii tuple<int, int, int>
#define tiiii tuple<int, int, int, int>
#define ff first
#define ss second
#define ee ss.ff
#define rr ss.ss
//#define DEBUG
using namespace std;
const int Q = (int)1e9 + 7;
const int X[10] = {3, 1, 18, 21, 9, 28, 6, 17, 30, 29};
vector<vector<int>> mul(const vector<vector<int>> &A, const vector<vector<int>> &B)
{
int n = A.size();
vector<vector<int>> C(n, vector<int>(n));
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
for(int k = 0; k < n; ++k)
C[i][k] = (C[i][k] + 1ll * A[i][j] * B[j][k] % Q) % Q;
return C;
}
vector<vector<int>> pow(vector<vector<int>> A, long long x)
{
int n = A.size();
vector<vector<int>> R(n, vector<int>(n));
for(int i = 0; i < n; ++i) R[i][i] = 1;
while(x)
{
if(x & 1) R = mul(R, A);
A = mul(A, A);
x >>= 1;
}
return R;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int m, x; long long n, k; cin >> m >> n >> k >> x;
vector<vector<int>> A(32, vector<int>(32));
for(int i = 0; i < 32; ++i)
for(int j = 0; j < 32; ++j)
if(__builtin_popcount(i ^ j) == 1) A[i][j] = 1;
#ifdef DEBUG
cout << endl;
cout << "A" << endl;
for(auto i : A)
{
for(auto j : i) cout << j << ' ';
cout << endl;
}
cout << endl;
#endif
auto B = pow(A, k);
auto C = pow(A, n % k);
#ifdef DEBUG
cout << endl;
cout << "A" << endl;
for(auto i : A)
{
for(auto j : i) cout << j << ' ';
cout << endl;
}
cout << endl;
#endif
vector<vector<int>> D(10, vector<int>(10)), E = D;
for(int i = 0; i < 10; ++i)
for(int j = 0; j < 10; ++j)
D[i][j] = B[X[i]][X[j]],
E[i][j] = C[X[i]][X[j]];
auto F = mul(pow(D, n / k), E);
int ans = 0;
for(int i = 0; i < 10; ++i) cout << F[x][i] << '\n';
}
Compilation message
semafor.cpp: In function 'int main()':
semafor.cpp:93:9: warning: unused variable 'ans' [-Wunused-variable]
93 | int ans = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
3 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
3 ms |
332 KB |
Output is correct |
6 |
Correct |
3 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
308 KB |
Output is correct |
9 |
Correct |
2 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
3 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
3 ms |
332 KB |
Output is correct |
6 |
Correct |
3 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
308 KB |
Output is correct |
9 |
Correct |
2 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
7 ms |
352 KB |
Output is correct |
12 |
Correct |
10 ms |
332 KB |
Output is correct |
13 |
Correct |
34 ms |
320 KB |
Output is correct |
14 |
Correct |
23 ms |
336 KB |
Output is correct |
15 |
Correct |
49 ms |
316 KB |
Output is correct |
16 |
Correct |
23 ms |
336 KB |
Output is correct |
17 |
Correct |
27 ms |
328 KB |
Output is correct |
18 |
Correct |
2 ms |
308 KB |
Output is correct |
19 |
Correct |
4 ms |
332 KB |
Output is correct |
20 |
Correct |
23 ms |
328 KB |
Output is correct |
21 |
Correct |
15 ms |
204 KB |
Output is correct |
22 |
Correct |
12 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |