#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll>> Mat;
const ll MOD = 1e9+7;
const int MM[10]={12, 8, 5, 25, 10, 19, 20, 9, 23, 27};
int M, X;
ll N, K;
Mat operator + (const Mat &p, const Mat &q)
{
Mat ret;
int sz=p.size();
ret=vector<vector<ll>>(sz, vector<ll>(sz));
for(int i=0; i<sz; i++)
{
for(int j=0; j<sz; j++)
{
ret[i][j]=0;
for(int k=0; k<sz; k++)
{
ret[i][j]+=p[i][k]*q[k][j]%MOD;
ret[i][j]%=MOD;
//if(ret[i][j]>=MOD) ret[i][j]-=MOD;
}
}
}
return ret;
}
Mat mypow(Mat x, ll y)
{
if(y==0)
{
int sz=x.size();
Mat ret=vector<vector<ll>>(sz, vector<ll>(sz, 0));
for(int i=0; i<sz; i++) ret[i][i]=1;
return ret;
}
if(y%2) return mypow(x, y-1)+x;
Mat ret=mypow(x, y/2);
return ret+ret;
}
Mat A, B, C;
Mat P, Q, R;
int main()
{
scanf("%d%lld%lld%d", &M, &N, &K, &X);
A=vector<vector<ll>>(32, vector<ll>(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;
}
}
B=mypow(A, K);
C=mypow(A, N%K);
P=vector<vector<ll>>(10, vector<ll>(10));
Q=vector<vector<ll>>(10, vector<ll>(10));
for(int i=0; i<10; i++)
{
for(int j=0; j<10; j++)
{
P[i][j]=B[MM[i]][MM[j]];
Q[i][j]=C[MM[i]][MM[j]];
}
}
R=mypow(P, N/K)+Q;
for(int i=0; i<10; i++)
{
printf("%lld\n", R[X][i]);
}
}
Compilation message
semafor.cpp: In function 'int main()':
semafor.cpp:56:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
56 | scanf("%d%lld%lld%d", &M, &N, &K, &X);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
7 ms |
492 KB |
Output is correct |
12 |
Correct |
11 ms |
620 KB |
Output is correct |
13 |
Correct |
19 ms |
876 KB |
Output is correct |
14 |
Correct |
26 ms |
1132 KB |
Output is correct |
15 |
Correct |
24 ms |
1152 KB |
Output is correct |
16 |
Correct |
26 ms |
1004 KB |
Output is correct |
17 |
Correct |
24 ms |
1132 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
3 ms |
492 KB |
Output is correct |
20 |
Correct |
26 ms |
1132 KB |
Output is correct |
21 |
Correct |
16 ms |
1132 KB |
Output is correct |
22 |
Correct |
13 ms |
1004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |