# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
774464 |
2023-07-05T18:21:34 Z |
vjudge1 |
Semafor (COI20_semafor) |
C++17 |
|
532 ms |
5380 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
int dp[55][100][100], dp2[55][100][100], dp3[100][100];
int fact[12];
int mod=1e9+7;
int v;
void f(){
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
}
int sum(int a, int b){
return (a+b)%mod;
}
int mul(int a, int b){
return (a*b)%mod;
}
int poww(int a, int b){
if(b==0) return 1;
int t=poww(a, b/2);
t=mul(t, t);
if(b&1) return mul(a, t);
return t;
}
int cc(int x){
return mul(fact[v], poww(mul(fact[x], fact[v-x]), mod-2));
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
//f();
int m, n, k, x; cin >> m >> n >> k >> x;
if(m==1) v=5;
else v=10;
k = min(k, n);
for(int i = 0; i < v+1; i++){
if(i>0) dp[0][i][i-1] = i;
if(i<v) dp[0][i][i+1] = v-i;
}
for(int l=1; l<55; l++){
for(int i=0; i<v+1; i++){
for(int j=0; j<v+1; j++){
for(int k=0; k<v+1; k++){
dp[l][i][k] = sum(dp[l][i][k], mul(dp[l-1][i][j], dp[l-1][j][k]));
}
}
}
}
vector<int> p(v+1);
p[0]=1;
for(int i=54; i>=0; i--){
if(!(k&(1ll<<i))) continue;
//for(auto i: p) cout<<i<<" ";
// cout<<"\n";
vector<int> sp(v+1);
for(int l=0; l<v+1; l++){
for(int j=0; j<v+1; j++){
//if(j==5) cout<<dp[i][l][j];
sp[j]=sum(sp[j], mul(p[l], dp[i][l][j]));
}
}
swap(sp, p);
}
//for(auto i: p) cout<<i<<" ";
fact[0]=1;
for(int i=1; i<v+1; i++){
fact[i] = mul(fact[i-1], i);
}
for(int i=0; i<v+1; i++){
p[i]=mul( p[i], poww(cc(i) , mod-2));
}
array<int, 10> c;
array<int, 100> d;
c={10, 8, 18, 28, 9, 21, 6, 24, 23, 29};
for(int i=0; i<10; i++){
for(int l=0; l<10; l++){
d[i*10+l] = c[i]*32+c[l];
}
}
if(m==1){
for(int i = 0; i<10; i++){
for(int l=0; l<10; l++){
int pf=0;
for(int t=0; t<10; t++){
if((c[i]&(1<<t))!=(c[l]&(1<<t))) pf++;
}
dp2[0][i][l] = p[pf];
//if(i==5) cout<<dp2[0][i][l]<<" "<<l<<"\n";
}
}
for(int i=1; i<55; i++){
for(int l=0; l<10; l++){
for(int j=0; j<10; j++){
for(int k=0; k<10; k++){
dp2[i][l][k] = sum(dp2[i][l][k], mul(dp2[i-1][l][j], dp2[i-1][j][k]));
}
}
}
}
vector<int> aa(10);
aa[x] = 1;
for(int i=48; i>=0; i--){
if(k<=n/(1ll<<i)){
int s=n/(k*(1ll<<i));
n-=s*(k*(1ll<<i));
for(int l=0; l<s; l++){
vector<int> sf(10);
for(int j=0; j<10; j++){
for(int kk=0; kk<10; kk++){
sf[kk] = sum(sf[kk], mul(dp2[i][j][kk], aa[j]));
}
}
swap(aa, sf);
}
}
}
vector<int> hm(6);
hm[0]=1;
for(int i=54; i>=0; i--){
if(!(n&(1ll<<i))) continue;
vector<int> sp(6);
for(int l=0; l<6; l++){
for(int j=0; j<6; j++){
sp[j]=sum(sp[j], mul(hm[l], dp[i][l][j]));
}
}
swap(sp, hm);
}
vector<int> ans(10);
for(int i=0; i<6; i++){
hm[i]=mul(hm[i], poww(cc(i), mod-2));
}
for(int l=0; l<10; l++){
for(int i=0; i<10; i++){
int g=0;
for(int t=0; t<10; t++){
if((c[i]&(1<<t))!=(c[l]&(1<<t))) g++;
}
ans[i]=sum(ans[i], mul(hm[g],aa[l]));
}
}
for(auto i: ans) cout<<i<<" \n";
}
if(m==2){
for(int i = 0; i<100; i++){
for(int l=0; l<100; l++){
int pf=0;
for(int t=0; t<11; t++){
if((d[i]&(1<<t))!=(d[l]&(1<<t))) pf++;
}
dp2[0][i][l] = p[pf];
//if(i==5) cout<<dp2[0][i][l]<<" "<<l<<"\n";
}
}
for(int i=1; i<55; i++){
for(int l=0; l<100; l++){
for(int j=0; j<100; j++){
for(int k=0; k<100; k++){
dp2[i][l][k] = sum(dp2[i][l][k], mul(dp2[i-1][l][j], dp2[i-1][j][k]));
}
}
}
}
vector<int> aa(100);
aa[x] = 1;
for(int i=54; i>=0; i--){
if(k<=n/(1ll<<i)){
int s=n/(k*(1ll<<i));
n-=s*(k*(1ll<<i));
for(int l=0; l<s; l++){
vector<int> sf(100);
for(int j=0; j<100; j++){
for(int kk=0; kk<100; kk++){
sf[kk] = sum(sf[kk], mul(dp2[i][j][kk], aa[j]));
}
}
swap(aa, sf);
}
}
}
vector<int> hm(11);
hm[0]=1;
for(int i=54; i>=0; i--){
if(!(n&(1ll<<i))) continue;
vector<int> sp(11);
for(int l=0; l<11; l++){
for(int j=0; j<11; j++){
sp[j]=sum(sp[j], mul(hm[l], dp[i][l][j]));
}
}
swap(sp, hm);
}
vector<int> ans(100);
for(int i=0; i<11; i++){
hm[i]=mul(hm[i], poww(cc(i), mod-2));
}
for(int l=0; l<100; l++){
for(int i=0; i<100; i++){
int g=0;
for(int t=0; t<11; t++){
if((d[i]&(1<<t))!=(d[l]&(1<<t))) g++;
}
ans[i]=sum(ans[i], mul(hm[g],aa[l]));
}
}
for(auto i: ans) cout<<i<<" \n";
}
}
Compilation message
semafor.cpp: In function 'void f()':
semafor.cpp:10:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | freopen("in.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
semafor.cpp:11:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | freopen("out.txt", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1364 KB |
Output is correct |
2 |
Correct |
2 ms |
1364 KB |
Output is correct |
3 |
Correct |
2 ms |
1364 KB |
Output is correct |
4 |
Correct |
2 ms |
1348 KB |
Output is correct |
5 |
Correct |
2 ms |
1364 KB |
Output is correct |
6 |
Correct |
2 ms |
1364 KB |
Output is correct |
7 |
Correct |
2 ms |
1348 KB |
Output is correct |
8 |
Correct |
2 ms |
1364 KB |
Output is correct |
9 |
Correct |
2 ms |
1364 KB |
Output is correct |
10 |
Correct |
2 ms |
1352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1364 KB |
Output is correct |
2 |
Correct |
2 ms |
1364 KB |
Output is correct |
3 |
Correct |
2 ms |
1364 KB |
Output is correct |
4 |
Correct |
2 ms |
1348 KB |
Output is correct |
5 |
Correct |
2 ms |
1364 KB |
Output is correct |
6 |
Correct |
2 ms |
1364 KB |
Output is correct |
7 |
Correct |
2 ms |
1348 KB |
Output is correct |
8 |
Correct |
2 ms |
1364 KB |
Output is correct |
9 |
Correct |
2 ms |
1364 KB |
Output is correct |
10 |
Correct |
2 ms |
1352 KB |
Output is correct |
11 |
Correct |
2 ms |
1356 KB |
Output is correct |
12 |
Correct |
2 ms |
1364 KB |
Output is correct |
13 |
Correct |
2 ms |
1348 KB |
Output is correct |
14 |
Correct |
2 ms |
1364 KB |
Output is correct |
15 |
Correct |
2 ms |
1364 KB |
Output is correct |
16 |
Correct |
2 ms |
1364 KB |
Output is correct |
17 |
Correct |
2 ms |
1348 KB |
Output is correct |
18 |
Correct |
2 ms |
1364 KB |
Output is correct |
19 |
Correct |
2 ms |
1364 KB |
Output is correct |
20 |
Correct |
2 ms |
1348 KB |
Output is correct |
21 |
Correct |
2 ms |
1364 KB |
Output is correct |
22 |
Correct |
2 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
528 ms |
5284 KB |
Output is correct |
2 |
Correct |
530 ms |
5252 KB |
Output is correct |
3 |
Correct |
527 ms |
5180 KB |
Output is correct |
4 |
Correct |
523 ms |
5244 KB |
Output is correct |
5 |
Correct |
528 ms |
5252 KB |
Output is correct |
6 |
Correct |
526 ms |
5280 KB |
Output is correct |
7 |
Correct |
529 ms |
5216 KB |
Output is correct |
8 |
Correct |
526 ms |
5228 KB |
Output is correct |
9 |
Correct |
526 ms |
5236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
530 ms |
5168 KB |
Output is correct |
2 |
Correct |
524 ms |
5200 KB |
Output is correct |
3 |
Correct |
526 ms |
5348 KB |
Output is correct |
4 |
Correct |
529 ms |
5160 KB |
Output is correct |
5 |
Correct |
526 ms |
5228 KB |
Output is correct |
6 |
Correct |
528 ms |
5184 KB |
Output is correct |
7 |
Correct |
529 ms |
5160 KB |
Output is correct |
8 |
Correct |
481 ms |
5180 KB |
Output is correct |
9 |
Correct |
482 ms |
5348 KB |
Output is correct |
10 |
Correct |
528 ms |
5240 KB |
Output is correct |
11 |
Correct |
480 ms |
5204 KB |
Output is correct |
12 |
Correct |
481 ms |
5264 KB |
Output is correct |
13 |
Correct |
526 ms |
5276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
530 ms |
5168 KB |
Output is correct |
2 |
Correct |
524 ms |
5200 KB |
Output is correct |
3 |
Correct |
526 ms |
5348 KB |
Output is correct |
4 |
Correct |
529 ms |
5160 KB |
Output is correct |
5 |
Correct |
526 ms |
5228 KB |
Output is correct |
6 |
Correct |
528 ms |
5184 KB |
Output is correct |
7 |
Correct |
529 ms |
5160 KB |
Output is correct |
8 |
Correct |
481 ms |
5180 KB |
Output is correct |
9 |
Correct |
482 ms |
5348 KB |
Output is correct |
10 |
Correct |
528 ms |
5240 KB |
Output is correct |
11 |
Correct |
480 ms |
5204 KB |
Output is correct |
12 |
Correct |
481 ms |
5264 KB |
Output is correct |
13 |
Correct |
526 ms |
5276 KB |
Output is correct |
14 |
Correct |
526 ms |
5232 KB |
Output is correct |
15 |
Correct |
529 ms |
5336 KB |
Output is correct |
16 |
Correct |
526 ms |
5172 KB |
Output is correct |
17 |
Correct |
528 ms |
5280 KB |
Output is correct |
18 |
Correct |
529 ms |
5196 KB |
Output is correct |
19 |
Correct |
528 ms |
5272 KB |
Output is correct |
20 |
Correct |
529 ms |
5180 KB |
Output is correct |
21 |
Correct |
492 ms |
5244 KB |
Output is correct |
22 |
Correct |
531 ms |
5240 KB |
Output is correct |
23 |
Correct |
531 ms |
5252 KB |
Output is correct |
24 |
Correct |
528 ms |
5172 KB |
Output is correct |
25 |
Correct |
532 ms |
5164 KB |
Output is correct |
26 |
Correct |
523 ms |
5212 KB |
Output is correct |
27 |
Correct |
532 ms |
5288 KB |
Output is correct |
28 |
Correct |
528 ms |
5224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
528 ms |
5284 KB |
Output is correct |
2 |
Correct |
530 ms |
5252 KB |
Output is correct |
3 |
Correct |
527 ms |
5180 KB |
Output is correct |
4 |
Correct |
523 ms |
5244 KB |
Output is correct |
5 |
Correct |
528 ms |
5252 KB |
Output is correct |
6 |
Correct |
526 ms |
5280 KB |
Output is correct |
7 |
Correct |
529 ms |
5216 KB |
Output is correct |
8 |
Correct |
526 ms |
5228 KB |
Output is correct |
9 |
Correct |
526 ms |
5236 KB |
Output is correct |
10 |
Correct |
530 ms |
5168 KB |
Output is correct |
11 |
Correct |
524 ms |
5200 KB |
Output is correct |
12 |
Correct |
526 ms |
5348 KB |
Output is correct |
13 |
Correct |
529 ms |
5160 KB |
Output is correct |
14 |
Correct |
526 ms |
5228 KB |
Output is correct |
15 |
Correct |
528 ms |
5184 KB |
Output is correct |
16 |
Correct |
529 ms |
5160 KB |
Output is correct |
17 |
Correct |
481 ms |
5180 KB |
Output is correct |
18 |
Correct |
482 ms |
5348 KB |
Output is correct |
19 |
Correct |
528 ms |
5240 KB |
Output is correct |
20 |
Correct |
480 ms |
5204 KB |
Output is correct |
21 |
Correct |
481 ms |
5264 KB |
Output is correct |
22 |
Correct |
526 ms |
5276 KB |
Output is correct |
23 |
Correct |
526 ms |
5232 KB |
Output is correct |
24 |
Correct |
529 ms |
5336 KB |
Output is correct |
25 |
Correct |
526 ms |
5172 KB |
Output is correct |
26 |
Correct |
528 ms |
5280 KB |
Output is correct |
27 |
Correct |
529 ms |
5196 KB |
Output is correct |
28 |
Correct |
528 ms |
5272 KB |
Output is correct |
29 |
Correct |
529 ms |
5180 KB |
Output is correct |
30 |
Correct |
492 ms |
5244 KB |
Output is correct |
31 |
Correct |
531 ms |
5240 KB |
Output is correct |
32 |
Correct |
531 ms |
5252 KB |
Output is correct |
33 |
Correct |
528 ms |
5172 KB |
Output is correct |
34 |
Correct |
532 ms |
5164 KB |
Output is correct |
35 |
Correct |
523 ms |
5212 KB |
Output is correct |
36 |
Correct |
532 ms |
5288 KB |
Output is correct |
37 |
Correct |
528 ms |
5224 KB |
Output is correct |
38 |
Correct |
526 ms |
5312 KB |
Output is correct |
39 |
Correct |
526 ms |
5160 KB |
Output is correct |
40 |
Correct |
526 ms |
5260 KB |
Output is correct |
41 |
Correct |
528 ms |
5280 KB |
Output is correct |
42 |
Correct |
527 ms |
5252 KB |
Output is correct |
43 |
Correct |
530 ms |
5208 KB |
Output is correct |
44 |
Correct |
527 ms |
5380 KB |
Output is correct |
45 |
Correct |
481 ms |
5200 KB |
Output is correct |
46 |
Correct |
527 ms |
5244 KB |
Output is correct |
47 |
Correct |
527 ms |
5252 KB |
Output is correct |
48 |
Correct |
526 ms |
5260 KB |
Output is correct |
49 |
Correct |
526 ms |
5152 KB |
Output is correct |
50 |
Correct |
527 ms |
5212 KB |
Output is correct |
51 |
Correct |
526 ms |
5176 KB |
Output is correct |
52 |
Correct |
527 ms |
5204 KB |
Output is correct |