Submission #966449

# Submission time Handle Problem Language Result Execution time Memory
966449 2024-04-19T22:15:49 Z jcelin Semafor (COI20_semafor) C++14
100 / 100
203 ms 724 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<pll> vpll;

#define PB push_back
#define PF push_front
#define PPB pop_back
#define PPF pop_front
#define X first
#define Y second
#define MP make_pair
#define all(x) (x).begin(), (x).end()

const int mod = 1e9 + 7; //998244353;
const int inf = 1e9 + 7;
const ll INF = 1e18 + 7;
const int logo = 20;
const int MAXN = 1e6 + 7;
const int off = 1 << logo;
const int trsz = off << 1;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};

vi vec = {10, 2, 9, 7, 18, 21, 12, 3, 29, 23}, svi;
int brojb, csz;

struct mat{
	int n;
	vector<vi> a;
	
	void res(int _n){
		n = _n;
		a.clear();
		a.resize(n, vi(n, 0));
	}
	
	void jed(){
		for(int i=0; i<n; i++) a[i][i] = 1;
	}
	
	void prin(){
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++) cout << a[i][j] << " ";
			cout << "\n";
		}
	}
}popc, rj, zamul;

int mul(ll a, ll b){
	return (a * b) % mod;
}

int add(int a, int b){
	a += b;
	if(a >= mod) a -= mod;
	return a;
}

int exp(int b, ll e){
	int ret = 1;
	while(e){
		if(e & 1) ret = mul(ret, b);
		b = mul(b, b);
		e /= (ll)2;
	}
	return ret;
}

int divide(ll a, ll b){
	return mul(a, exp(b, mod - 2));
}

int ch[12][12];

void pre(){
	for(int i=0; i<12; i++){
		ch[i][0] = 1;
		for(int j=1; j<=i; j++){
			ch[i][j] = add(ch[i - 1][j], ch[i - 1][j - 1]);
		}
	}
}

mat operator *(mat &a, mat &b){
	int n = a.n;
	mat c;
	c.res(n);
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			for(int k=0; k<n; k++){
				c.a[i][j] = add(c.a[i][j], mul(a.a[i][k], b.a[k][j]));
			}
		}
	}
	return c;
}

void pripremi(){
	popc.res(brojb + 1);
	for(int i=0; i<=brojb; i++){
		if(i != brojb) popc.a[i][i + 1] = brojb - i;
		if(i) popc.a[i][i - 1] = i;
	}
}

mat expm(mat b, ll e){
	mat ret;
	ret.res(b.n);
	ret.jed();
	while(e){
		if(e & 1) ret = ret * b;
		b = b * b;
		e /= (ll)2;
	}
	return ret;
}

void pripremi2(){
	zamul.res(csz);
	for(int i=0; i<csz; i++){
		for(int j=0; j<csz; j++){
			int c = __builtin_popcount(vec[i] ^ vec[j]);
			zamul.a[i][j] = divide(popc.a[0][c], ch[brojb][c]);
		}
	}
}

void mnozi(ll e1, ll e2){
	pripremi();
	popc = expm(popc, e1);
	pripremi2();
	zamul = expm(zamul, e2);
	rj = rj * zamul;
}

void solve(){
	ll n, m, k, x;
	cin >> m >> n >> k >> x;
	
	brojb = 5 * m;
	if(m == 1) csz = 10;
	else{
		csz = 100;
		for(int i=0; i<csz; i++){
			int a = vec[i / 10];
			int b = vec[i % 10];
			svi.PB((a << 5) | b);
		}
		swap(svi, vec);
	}
	
	rj.res(csz);
	rj.a[x][x] = 1;
	
	mnozi(k, n / k);
	if(n % k) mnozi(n % k, 1);
	
	for(int i=0; i<csz; i++) cout << rj.a[x][i] << "\n";
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	pre();
	solve();
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 600 KB Output is correct
2 Correct 9 ms 604 KB Output is correct
3 Correct 9 ms 460 KB Output is correct
4 Correct 10 ms 604 KB Output is correct
5 Correct 9 ms 604 KB Output is correct
6 Correct 12 ms 600 KB Output is correct
7 Correct 9 ms 604 KB Output is correct
8 Correct 9 ms 604 KB Output is correct
9 Correct 9 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 600 KB Output is correct
2 Correct 101 ms 656 KB Output is correct
3 Correct 163 ms 656 KB Output is correct
4 Correct 200 ms 656 KB Output is correct
5 Correct 188 ms 652 KB Output is correct
6 Correct 180 ms 604 KB Output is correct
7 Correct 195 ms 600 KB Output is correct
8 Correct 178 ms 600 KB Output is correct
9 Correct 203 ms 604 KB Output is correct
10 Correct 187 ms 656 KB Output is correct
11 Correct 25 ms 600 KB Output is correct
12 Correct 12 ms 672 KB Output is correct
13 Correct 190 ms 652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 600 KB Output is correct
2 Correct 101 ms 656 KB Output is correct
3 Correct 163 ms 656 KB Output is correct
4 Correct 200 ms 656 KB Output is correct
5 Correct 188 ms 652 KB Output is correct
6 Correct 180 ms 604 KB Output is correct
7 Correct 195 ms 600 KB Output is correct
8 Correct 178 ms 600 KB Output is correct
9 Correct 203 ms 604 KB Output is correct
10 Correct 187 ms 656 KB Output is correct
11 Correct 25 ms 600 KB Output is correct
12 Correct 12 ms 672 KB Output is correct
13 Correct 190 ms 652 KB Output is correct
14 Correct 35 ms 724 KB Output is correct
15 Correct 82 ms 600 KB Output is correct
16 Correct 119 ms 600 KB Output is correct
17 Correct 153 ms 600 KB Output is correct
18 Correct 174 ms 600 KB Output is correct
19 Correct 143 ms 604 KB Output is correct
20 Correct 166 ms 648 KB Output is correct
21 Correct 177 ms 604 KB Output is correct
22 Correct 186 ms 656 KB Output is correct
23 Correct 154 ms 600 KB Output is correct
24 Correct 160 ms 648 KB Output is correct
25 Correct 158 ms 600 KB Output is correct
26 Correct 23 ms 600 KB Output is correct
27 Correct 28 ms 604 KB Output is correct
28 Correct 122 ms 652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 600 KB Output is correct
2 Correct 9 ms 604 KB Output is correct
3 Correct 9 ms 460 KB Output is correct
4 Correct 10 ms 604 KB Output is correct
5 Correct 9 ms 604 KB Output is correct
6 Correct 12 ms 600 KB Output is correct
7 Correct 9 ms 604 KB Output is correct
8 Correct 9 ms 604 KB Output is correct
9 Correct 9 ms 604 KB Output is correct
10 Correct 48 ms 600 KB Output is correct
11 Correct 101 ms 656 KB Output is correct
12 Correct 163 ms 656 KB Output is correct
13 Correct 200 ms 656 KB Output is correct
14 Correct 188 ms 652 KB Output is correct
15 Correct 180 ms 604 KB Output is correct
16 Correct 195 ms 600 KB Output is correct
17 Correct 178 ms 600 KB Output is correct
18 Correct 203 ms 604 KB Output is correct
19 Correct 187 ms 656 KB Output is correct
20 Correct 25 ms 600 KB Output is correct
21 Correct 12 ms 672 KB Output is correct
22 Correct 190 ms 652 KB Output is correct
23 Correct 35 ms 724 KB Output is correct
24 Correct 82 ms 600 KB Output is correct
25 Correct 119 ms 600 KB Output is correct
26 Correct 153 ms 600 KB Output is correct
27 Correct 174 ms 600 KB Output is correct
28 Correct 143 ms 604 KB Output is correct
29 Correct 166 ms 648 KB Output is correct
30 Correct 177 ms 604 KB Output is correct
31 Correct 186 ms 656 KB Output is correct
32 Correct 154 ms 600 KB Output is correct
33 Correct 160 ms 648 KB Output is correct
34 Correct 158 ms 600 KB Output is correct
35 Correct 23 ms 600 KB Output is correct
36 Correct 28 ms 604 KB Output is correct
37 Correct 122 ms 652 KB Output is correct
38 Correct 21 ms 604 KB Output is correct
39 Correct 19 ms 604 KB Output is correct
40 Correct 21 ms 604 KB Output is correct
41 Correct 19 ms 604 KB Output is correct
42 Correct 19 ms 604 KB Output is correct
43 Correct 19 ms 604 KB Output is correct
44 Correct 19 ms 604 KB Output is correct
45 Correct 176 ms 652 KB Output is correct
46 Correct 172 ms 652 KB Output is correct
47 Correct 21 ms 460 KB Output is correct
48 Correct 19 ms 600 KB Output is correct
49 Correct 10 ms 600 KB Output is correct
50 Correct 9 ms 604 KB Output is correct
51 Correct 18 ms 604 KB Output is correct
52 Correct 69 ms 672 KB Output is correct