Submission #774461

# Submission time Handle Problem Language Result Execution time Memory
774461 2023-07-05T18:17:12 Z vjudge1 Semafor (COI20_semafor) C++17
79 / 100
538 ms 5452 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;

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[10], poww(mul(fact[x], fact[10-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;
		
	k = min(k, n);

	for(int i = 0; i < 11; i++){
		if(i>0) dp[0][i][i-1] = i;
		if(i<10) dp[0][i][i+1] = 10-i;
	}

	for(int l=1; l<55; l++){
		for(int i=0; i<11; i++){
			for(int j=0; j<11; j++){
				for(int k=0; k<11; k++){
					dp[l][i][k] = sum(dp[l][i][k], mul(dp[l-1][i][j], dp[l-1][j][k]));
				}
			}
		}
	}



	vector<int> p(11);
	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(11);
		for(int l=0; l<11; l++){
			for(int j=0; j<11; 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<11; i++){
		fact[i] = mul(fact[i-1], i);
	}


	for(int i=0; i<11; 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==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:9:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |  freopen("in.txt", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
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("out.txt", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 529 ms 5248 KB Output is correct
2 Correct 528 ms 5288 KB Output is correct
3 Correct 530 ms 5268 KB Output is correct
4 Correct 525 ms 5164 KB Output is correct
5 Correct 528 ms 5216 KB Output is correct
6 Correct 529 ms 5284 KB Output is correct
7 Correct 527 ms 5164 KB Output is correct
8 Correct 531 ms 5240 KB Output is correct
9 Correct 527 ms 5220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 528 ms 5180 KB Output is correct
2 Correct 526 ms 5240 KB Output is correct
3 Correct 535 ms 5252 KB Output is correct
4 Correct 538 ms 5244 KB Output is correct
5 Correct 530 ms 5168 KB Output is correct
6 Correct 529 ms 5200 KB Output is correct
7 Correct 531 ms 5280 KB Output is correct
8 Correct 484 ms 5232 KB Output is correct
9 Correct 485 ms 5164 KB Output is correct
10 Correct 530 ms 5200 KB Output is correct
11 Correct 480 ms 5252 KB Output is correct
12 Correct 480 ms 5280 KB Output is correct
13 Correct 525 ms 5176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 528 ms 5180 KB Output is correct
2 Correct 526 ms 5240 KB Output is correct
3 Correct 535 ms 5252 KB Output is correct
4 Correct 538 ms 5244 KB Output is correct
5 Correct 530 ms 5168 KB Output is correct
6 Correct 529 ms 5200 KB Output is correct
7 Correct 531 ms 5280 KB Output is correct
8 Correct 484 ms 5232 KB Output is correct
9 Correct 485 ms 5164 KB Output is correct
10 Correct 530 ms 5200 KB Output is correct
11 Correct 480 ms 5252 KB Output is correct
12 Correct 480 ms 5280 KB Output is correct
13 Correct 525 ms 5176 KB Output is correct
14 Correct 528 ms 5256 KB Output is correct
15 Correct 527 ms 5192 KB Output is correct
16 Correct 528 ms 5248 KB Output is correct
17 Correct 529 ms 5180 KB Output is correct
18 Correct 530 ms 5280 KB Output is correct
19 Correct 528 ms 5160 KB Output is correct
20 Correct 527 ms 5196 KB Output is correct
21 Correct 483 ms 5224 KB Output is correct
22 Correct 529 ms 5204 KB Output is correct
23 Correct 532 ms 5260 KB Output is correct
24 Correct 532 ms 5184 KB Output is correct
25 Correct 532 ms 5332 KB Output is correct
26 Correct 525 ms 5200 KB Output is correct
27 Correct 526 ms 5212 KB Output is correct
28 Correct 531 ms 5452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 529 ms 5248 KB Output is correct
2 Correct 528 ms 5288 KB Output is correct
3 Correct 530 ms 5268 KB Output is correct
4 Correct 525 ms 5164 KB Output is correct
5 Correct 528 ms 5216 KB Output is correct
6 Correct 529 ms 5284 KB Output is correct
7 Correct 527 ms 5164 KB Output is correct
8 Correct 531 ms 5240 KB Output is correct
9 Correct 527 ms 5220 KB Output is correct
10 Correct 528 ms 5180 KB Output is correct
11 Correct 526 ms 5240 KB Output is correct
12 Correct 535 ms 5252 KB Output is correct
13 Correct 538 ms 5244 KB Output is correct
14 Correct 530 ms 5168 KB Output is correct
15 Correct 529 ms 5200 KB Output is correct
16 Correct 531 ms 5280 KB Output is correct
17 Correct 484 ms 5232 KB Output is correct
18 Correct 485 ms 5164 KB Output is correct
19 Correct 530 ms 5200 KB Output is correct
20 Correct 480 ms 5252 KB Output is correct
21 Correct 480 ms 5280 KB Output is correct
22 Correct 525 ms 5176 KB Output is correct
23 Correct 528 ms 5256 KB Output is correct
24 Correct 527 ms 5192 KB Output is correct
25 Correct 528 ms 5248 KB Output is correct
26 Correct 529 ms 5180 KB Output is correct
27 Correct 530 ms 5280 KB Output is correct
28 Correct 528 ms 5160 KB Output is correct
29 Correct 527 ms 5196 KB Output is correct
30 Correct 483 ms 5224 KB Output is correct
31 Correct 529 ms 5204 KB Output is correct
32 Correct 532 ms 5260 KB Output is correct
33 Correct 532 ms 5184 KB Output is correct
34 Correct 532 ms 5332 KB Output is correct
35 Correct 525 ms 5200 KB Output is correct
36 Correct 526 ms 5212 KB Output is correct
37 Correct 531 ms 5452 KB Output is correct
38 Correct 528 ms 5264 KB Output is correct
39 Correct 526 ms 5156 KB Output is correct
40 Correct 526 ms 5196 KB Output is correct
41 Correct 527 ms 5244 KB Output is correct
42 Correct 529 ms 5248 KB Output is correct
43 Correct 526 ms 5248 KB Output is correct
44 Correct 526 ms 5200 KB Output is correct
45 Correct 488 ms 5224 KB Output is correct
46 Correct 527 ms 5260 KB Output is correct
47 Correct 527 ms 5212 KB Output is correct
48 Correct 529 ms 5212 KB Output is correct
49 Correct 527 ms 5276 KB Output is correct
50 Correct 530 ms 5232 KB Output is correct
51 Correct 526 ms 5260 KB Output is correct
52 Correct 527 ms 5220 KB Output is correct