Submission #288131

# Submission time Handle Problem Language Result Execution time Memory
288131 2020-09-01T08:57:58 Z dvdg6566 "The Lyuboyn" code (IZhO19_lyuboyn) C++14
100 / 100
76 ms 6520 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;
#define pb emplace_back
#define mp make_pair
#define f first
#define s second
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(),x.end()
#define lb lower_bound
const int MAXN=1001000;
const ll MOD=998244353;

int N,K,T;
string S;

void tobin(int y,int len){
	string x;
	while(y){
		x+=('0' + y%2);
		y/=2;
	}
	while(SZ(x) < len)x+='0';
	reverse(ALL(x));
	cout<<x;
}

vector<int> generate(int N,int K){
	// cerr<<N<<' '<<K<<'\n';
	int mod=(1<<(N-K+1));
	vi A;
	A.resize((1<<N),0);
	ll alen=(K-1);
	int ind=0;

	int backf = min(K-1, N-K+1);
	int frontf = K-backf;
	if(frontf%2==0){
		++frontf;
		--backf;
	}
	// cerr<<backf<<' '<<frontf<<'\n';
	vi B;
	if(frontf > 1){
		B = generate(K-1, frontf);
		// for(auto i:B)cerr<<i<<' ';cerr<<'\n';
	}
	int ind2=0;

	for(int i=1;i<=(1<<alen);++i){
		for(int j=0;j<mod-1;++j){
			
			A[ind] += ((1<<alen) - 1) * mod;
			++ind;
			// A.pb(A.back() ^ ((1<<alen)-1));
		}
		if(frontf == 1) A[ind] += (i&(-i))*mod;
		else{
			A[ind] += B[ind2]*mod;
			++ind2;
		}
		++ind;
		// flip A back
		// if(SZ(A) < (1<<N))A.pb(A.back() ^ (i&(-i)));
	}

	// for(auto i:A)cerr<<i<<' ';cerr<<'\n';
	ind=0;
	for(int i=1;i<=(1<<alen);++i){
		for(int j=1;j<mod;++j){
			// B.pb(B.back() ^ (j&(-j)));
			A[ind] += (j&(-j));
			++ind;
		}
		A[ind] += (1<<backf)-1;
		++ind;
		// flip A back
		// if(SZ(B) < (1<<N))B.pb(B.back() ^ ((1<<(K-1))-1));
	}
	// for(auto i:A)cerr<<i<<' ';cerr<<'\n';
	return A;
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>N>>K>>T>>S;
	if(K%2==0){
		cout<<-1;
		return 0;
	}

	ll v=0;ll k=1;
	while(SZ(S)){
		if(S.back() == '1')v+=k;
		k*=2;
		S.pop_back();
	}

	vi A = generate(N,K);

	cout<<(1<<N)<<'\n';
	tobin(v,N);cout<<'\n';
	for(int i=0;i<((1<<N)-1);++i){
		v ^= A[i];
		tobin(v,N);cout<<'\n';
	}

	// for(int i=0;i<SZ(A);++i){
	// 	// if(flip&&i%2){
	// 	// 	A[i]=((1<<(K-1))-1)^A[i];
	// 	// 	B[i]=((1<<(N-K+1))-1)^B[i];
	// 	// }
	// 	tobin(B[i],(N-K+1));
	// 	tobin(A[i],K-1);
	// 	cout<<'\n';
	// }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Ok
2 Correct 0 ms 384 KB Ok
3 Correct 0 ms 384 KB Ok
4 Correct 1 ms 384 KB Ok
5 Correct 0 ms 384 KB Ok
6 Correct 0 ms 384 KB Ok
7 Correct 0 ms 384 KB Ok
8 Correct 0 ms 384 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 70 ms 6392 KB Ok
2 Correct 34 ms 3200 KB Ok
3 Correct 1 ms 384 KB Ok
4 Correct 0 ms 384 KB Ok
5 Correct 0 ms 384 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Ok
2 Correct 2 ms 512 KB Ok
3 Correct 34 ms 3192 KB Ok
4 Correct 16 ms 1664 KB Ok
5 Correct 1 ms 384 KB Ok
6 Correct 1 ms 384 KB Ok
7 Correct 7 ms 1024 KB Ok
8 Correct 0 ms 384 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 71 ms 6392 KB Ok
2 Correct 71 ms 6404 KB Ok
3 Correct 71 ms 6392 KB Ok
4 Correct 33 ms 3200 KB Ok
5 Correct 34 ms 3192 KB Ok
6 Correct 16 ms 1664 KB Ok
7 Correct 16 ms 1768 KB Ok
8 Correct 7 ms 1024 KB Ok
9 Correct 7 ms 1024 KB Ok
10 Correct 4 ms 640 KB Ok
11 Correct 1 ms 384 KB Ok
12 Correct 1 ms 384 KB Ok
13 Correct 0 ms 384 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 70 ms 6392 KB Ok
2 Correct 34 ms 3200 KB Ok
3 Correct 1 ms 384 KB Ok
4 Correct 0 ms 384 KB Ok
5 Correct 0 ms 384 KB Ok
6 Correct 0 ms 384 KB Ok
7 Correct 2 ms 512 KB Ok
8 Correct 34 ms 3192 KB Ok
9 Correct 16 ms 1664 KB Ok
10 Correct 1 ms 384 KB Ok
11 Correct 1 ms 384 KB Ok
12 Correct 7 ms 1024 KB Ok
13 Correct 0 ms 384 KB Ok
14 Correct 71 ms 6392 KB Ok
15 Correct 71 ms 6404 KB Ok
16 Correct 71 ms 6392 KB Ok
17 Correct 33 ms 3200 KB Ok
18 Correct 34 ms 3192 KB Ok
19 Correct 16 ms 1664 KB Ok
20 Correct 16 ms 1768 KB Ok
21 Correct 7 ms 1024 KB Ok
22 Correct 7 ms 1024 KB Ok
23 Correct 4 ms 640 KB Ok
24 Correct 1 ms 384 KB Ok
25 Correct 1 ms 384 KB Ok
26 Correct 0 ms 384 KB Ok
27 Correct 76 ms 6388 KB Ok
28 Correct 34 ms 3192 KB Ok
29 Correct 71 ms 6468 KB Ok
30 Correct 3 ms 640 KB Ok
31 Correct 1 ms 384 KB Ok
32 Correct 2 ms 512 KB Ok
33 Correct 6 ms 1024 KB Ok
34 Correct 0 ms 384 KB Ok
35 Correct 0 ms 384 KB Ok
36 Correct 1 ms 384 KB Ok
37 Correct 0 ms 384 KB Ok
38 Correct 34 ms 3328 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 35 ms 3320 KB Ok
2 Correct 72 ms 6388 KB Ok
3 Correct 69 ms 6520 KB Ok
4 Correct 4 ms 640 KB Ok
5 Correct 0 ms 384 KB Ok
6 Correct 7 ms 1024 KB Ok
7 Correct 69 ms 6392 KB Ok
8 Correct 1 ms 384 KB Ok
9 Correct 0 ms 384 KB Ok
10 Correct 1 ms 384 KB Ok
11 Correct 18 ms 1792 KB Ok
12 Correct 36 ms 3296 KB Ok