# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
560540 |
2022-05-11T16:48:29 Z |
leaked |
Semafor (COI20_semafor) |
C++17 |
|
279 ms |
720 KB |
#include <bits/stdc++.h>
#define f first
#define s second
#define m_p make_pair
#define vec vector
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)(x).size()
#define pw(x) (1LL<<(x))
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}
template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
const int N=1e2+1;
const int M=1e9+7;
const ll MOD=1ll*M*M;
struct mat{
int a[N][N];
mat(){
for(int i=0;i<N;i++){
for(int j=0;j<N;j++)
a[i][j]=0;
}
}
mat operator *(const mat &o){
mat c;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
ll cur=0;
for(int k=0;k<N;k++){
cur+=1ll*a[i][k]*o.a[k][j];
if(cur>=MOD)
cur-=MOD;
}
c.a[i][j]=cur%M;
}
}
return c;
}
};
mat binpow(mat a,int x,ll k){
mat ans;
ans.a[x][x]=1;
while(k){
if(k&1) ans=ans*a;
a=a*a;k>>=1;
}
return ans;
}
int binpowt(int a,int b){
int ans=1;
while(b){
if(b&1) ans=1ll*ans*a%M;
a=1ll*a*a%M;b>>=1;
}
return ans;
}
int C[N][N];
int inv(int x){
return binpowt(x,M-2);
}
int mult(int a,int b){
return 1ll*a*b%M;
}
int di[10];
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
di[1]=0+2+0+0+0;
di[2]=1+0+0+8+0;
di[3]=1+2+4+0+0;
di[4]=0+2+0+0+16;
di[5]=1+0+4+0+16;
di[6]=0+0+4+8+0;
di[7]=1+2+0+0+0;
di[8]=1+0+4+8+16;
di[9]=1+2+4+0+16;
di[0]=0+2+0+8+0;
C[0][0]=1;
for(int i=1;i<N;i++){
for(int j=0;j<=i;j++){
C[j][i]=C[j][i-1]+(j?C[j-1][i-1]:0);
C[j][i]%=M;
}
}
int m;ll n,k;
int x;
cin>>m>>n>>k>>x;
mat me;
for(int i=0;i<=5*m;i++){
if((i-1)>=0)
me.a[i][i-1]=i;
if(i+1<=(5*m))
me.a[i][i+1]=(5*m-i);
// for(int j=0;j<=5*m;j++)
// cout<<me.a[i][j]<<' ';
// cout<<endl;
}
mat yo=binpow(me,0,k);
mat yo1=binpow(me,0,n%k);
mat o,o1;
for(int i=0;i<(m==1?10:100);i++){
for(int j=0;j<(m==1?10:100);j++){
int fi=(m==1?__builtin_popcount(di[i]^di[j]):__builtin_popcount(di[i%10]^di[j%10])+__builtin_popcount(di[i/10]^di[j/10]));
o.a[i][j]=mult(inv(C[fi][5*m]),yo.a[0][fi]);
// cout<<"GO "<<i<<' '<<j<<' '<<' '<<fi<<' '<<o.a[i][j]<<' '<<C[fi][5*m]<<endl;
o1.a[i][j]=mult(inv(C[fi][5*m]),yo1.a[0][fi]);
}
}
// for(int i=0;i<(m==1?10:100);i++){
// for(int j=0;j<(m==1?10:100);j++){
// cout<<o.a[i][j]<<' ';
// }
// cout<<'\n';
// }
o=binpow(o,x,n/k);
// for(int i=0;i<(m==1?10:100);i++){
// for(int j=0;j<(m==1?10:100);j++){
// cout<<o.a[i][j]<<' ';
// }
// cout<<'\n';
// }
o=o*o1;
for(int x=0;x<(m==1?10:100);x++){
int cur=0;
for(int y=0;y<(m==1?10:100);y++){
cur+=o.a[y][x];
cur%=M;
}
cout<<cur<<'\n';
}
return 0;
}
/*
10 1
2 5 8 4 10 7 9 6 1
3
1 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
596 KB |
Output is correct |
2 |
Correct |
16 ms |
596 KB |
Output is correct |
3 |
Correct |
21 ms |
596 KB |
Output is correct |
4 |
Correct |
15 ms |
720 KB |
Output is correct |
5 |
Correct |
24 ms |
716 KB |
Output is correct |
6 |
Correct |
18 ms |
596 KB |
Output is correct |
7 |
Correct |
25 ms |
596 KB |
Output is correct |
8 |
Correct |
18 ms |
636 KB |
Output is correct |
9 |
Correct |
18 ms |
716 KB |
Output is correct |
10 |
Correct |
16 ms |
712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
596 KB |
Output is correct |
2 |
Correct |
16 ms |
596 KB |
Output is correct |
3 |
Correct |
21 ms |
596 KB |
Output is correct |
4 |
Correct |
15 ms |
720 KB |
Output is correct |
5 |
Correct |
24 ms |
716 KB |
Output is correct |
6 |
Correct |
18 ms |
596 KB |
Output is correct |
7 |
Correct |
25 ms |
596 KB |
Output is correct |
8 |
Correct |
18 ms |
636 KB |
Output is correct |
9 |
Correct |
18 ms |
716 KB |
Output is correct |
10 |
Correct |
16 ms |
712 KB |
Output is correct |
11 |
Correct |
70 ms |
632 KB |
Output is correct |
12 |
Correct |
112 ms |
596 KB |
Output is correct |
13 |
Correct |
204 ms |
716 KB |
Output is correct |
14 |
Correct |
250 ms |
636 KB |
Output is correct |
15 |
Correct |
253 ms |
700 KB |
Output is correct |
16 |
Correct |
279 ms |
696 KB |
Output is correct |
17 |
Correct |
253 ms |
700 KB |
Output is correct |
18 |
Correct |
129 ms |
688 KB |
Output is correct |
19 |
Correct |
134 ms |
696 KB |
Output is correct |
20 |
Correct |
245 ms |
700 KB |
Output is correct |
21 |
Correct |
160 ms |
596 KB |
Output is correct |
22 |
Correct |
118 ms |
696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
596 KB |
Output is correct |
2 |
Correct |
25 ms |
596 KB |
Output is correct |
3 |
Correct |
34 ms |
596 KB |
Output is correct |
4 |
Correct |
34 ms |
596 KB |
Output is correct |
5 |
Correct |
32 ms |
596 KB |
Output is correct |
6 |
Correct |
38 ms |
704 KB |
Output is correct |
7 |
Correct |
45 ms |
596 KB |
Output is correct |
8 |
Correct |
45 ms |
696 KB |
Output is correct |
9 |
Correct |
32 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
596 KB |
Output is correct |
2 |
Correct |
73 ms |
692 KB |
Output is correct |
3 |
Correct |
124 ms |
712 KB |
Output is correct |
4 |
Correct |
154 ms |
696 KB |
Output is correct |
5 |
Correct |
127 ms |
596 KB |
Output is correct |
6 |
Correct |
149 ms |
704 KB |
Output is correct |
7 |
Correct |
142 ms |
700 KB |
Output is correct |
8 |
Correct |
125 ms |
596 KB |
Output is correct |
9 |
Correct |
125 ms |
692 KB |
Output is correct |
10 |
Correct |
158 ms |
696 KB |
Output is correct |
11 |
Correct |
20 ms |
716 KB |
Output is correct |
12 |
Correct |
12 ms |
632 KB |
Output is correct |
13 |
Correct |
131 ms |
696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
596 KB |
Output is correct |
2 |
Correct |
73 ms |
692 KB |
Output is correct |
3 |
Correct |
124 ms |
712 KB |
Output is correct |
4 |
Correct |
154 ms |
696 KB |
Output is correct |
5 |
Correct |
127 ms |
596 KB |
Output is correct |
6 |
Correct |
149 ms |
704 KB |
Output is correct |
7 |
Correct |
142 ms |
700 KB |
Output is correct |
8 |
Correct |
125 ms |
596 KB |
Output is correct |
9 |
Correct |
125 ms |
692 KB |
Output is correct |
10 |
Correct |
158 ms |
696 KB |
Output is correct |
11 |
Correct |
20 ms |
716 KB |
Output is correct |
12 |
Correct |
12 ms |
632 KB |
Output is correct |
13 |
Correct |
131 ms |
696 KB |
Output is correct |
14 |
Correct |
60 ms |
708 KB |
Output is correct |
15 |
Correct |
107 ms |
708 KB |
Output is correct |
16 |
Correct |
132 ms |
712 KB |
Output is correct |
17 |
Correct |
152 ms |
692 KB |
Output is correct |
18 |
Correct |
172 ms |
696 KB |
Output is correct |
19 |
Correct |
133 ms |
596 KB |
Output is correct |
20 |
Correct |
151 ms |
596 KB |
Output is correct |
21 |
Correct |
120 ms |
696 KB |
Output is correct |
22 |
Correct |
143 ms |
692 KB |
Output is correct |
23 |
Correct |
152 ms |
596 KB |
Output is correct |
24 |
Correct |
154 ms |
704 KB |
Output is correct |
25 |
Correct |
162 ms |
596 KB |
Output is correct |
26 |
Correct |
22 ms |
720 KB |
Output is correct |
27 |
Correct |
30 ms |
596 KB |
Output is correct |
28 |
Correct |
139 ms |
696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
596 KB |
Output is correct |
2 |
Correct |
25 ms |
596 KB |
Output is correct |
3 |
Correct |
34 ms |
596 KB |
Output is correct |
4 |
Correct |
34 ms |
596 KB |
Output is correct |
5 |
Correct |
32 ms |
596 KB |
Output is correct |
6 |
Correct |
38 ms |
704 KB |
Output is correct |
7 |
Correct |
45 ms |
596 KB |
Output is correct |
8 |
Correct |
45 ms |
696 KB |
Output is correct |
9 |
Correct |
32 ms |
596 KB |
Output is correct |
10 |
Correct |
46 ms |
596 KB |
Output is correct |
11 |
Correct |
73 ms |
692 KB |
Output is correct |
12 |
Correct |
124 ms |
712 KB |
Output is correct |
13 |
Correct |
154 ms |
696 KB |
Output is correct |
14 |
Correct |
127 ms |
596 KB |
Output is correct |
15 |
Correct |
149 ms |
704 KB |
Output is correct |
16 |
Correct |
142 ms |
700 KB |
Output is correct |
17 |
Correct |
125 ms |
596 KB |
Output is correct |
18 |
Correct |
125 ms |
692 KB |
Output is correct |
19 |
Correct |
158 ms |
696 KB |
Output is correct |
20 |
Correct |
20 ms |
716 KB |
Output is correct |
21 |
Correct |
12 ms |
632 KB |
Output is correct |
22 |
Correct |
131 ms |
696 KB |
Output is correct |
23 |
Correct |
60 ms |
708 KB |
Output is correct |
24 |
Correct |
107 ms |
708 KB |
Output is correct |
25 |
Correct |
132 ms |
712 KB |
Output is correct |
26 |
Correct |
152 ms |
692 KB |
Output is correct |
27 |
Correct |
172 ms |
696 KB |
Output is correct |
28 |
Correct |
133 ms |
596 KB |
Output is correct |
29 |
Correct |
151 ms |
596 KB |
Output is correct |
30 |
Correct |
120 ms |
696 KB |
Output is correct |
31 |
Correct |
143 ms |
692 KB |
Output is correct |
32 |
Correct |
152 ms |
596 KB |
Output is correct |
33 |
Correct |
154 ms |
704 KB |
Output is correct |
34 |
Correct |
162 ms |
596 KB |
Output is correct |
35 |
Correct |
22 ms |
720 KB |
Output is correct |
36 |
Correct |
30 ms |
596 KB |
Output is correct |
37 |
Correct |
139 ms |
696 KB |
Output is correct |
38 |
Correct |
71 ms |
704 KB |
Output is correct |
39 |
Correct |
141 ms |
696 KB |
Output is correct |
40 |
Correct |
211 ms |
692 KB |
Output is correct |
41 |
Correct |
272 ms |
692 KB |
Output is correct |
42 |
Correct |
226 ms |
696 KB |
Output is correct |
43 |
Correct |
277 ms |
692 KB |
Output is correct |
44 |
Correct |
267 ms |
692 KB |
Output is correct |
45 |
Correct |
119 ms |
696 KB |
Output is correct |
46 |
Correct |
121 ms |
596 KB |
Output is correct |
47 |
Correct |
268 ms |
704 KB |
Output is correct |
48 |
Correct |
151 ms |
708 KB |
Output is correct |
49 |
Correct |
120 ms |
640 KB |
Output is correct |
50 |
Correct |
21 ms |
596 KB |
Output is correct |
51 |
Correct |
45 ms |
596 KB |
Output is correct |
52 |
Correct |
225 ms |
692 KB |
Output is correct |