Submission #911215

#TimeUsernameProblemLanguageResultExecution timeMemory
911215daoquanglinh2007"The Lyuboyn" code (IZhO19_lyuboyn)C++17
100 / 100
206 ms9920 KiB
#include <bits/stdc++.h> using namespace std; #define flipbit(x, i) x ^= (1<<(i)) const int a[] = {0, 7, 9, 2, 5, 8, 3, 4, 10, 1, 6, 11, 12, 16, 23, 13, 17, 22, 15, 19, 20, 14, 18, 21, 24, 31, 39, 32, 43, 25, 30, 38, 33, 42, 27, 28, 36, 35, 40, 26, 29, 37, 34, 41, 46, 50, 53, 44, 48, 55, 45, 49, 54, 59, 60, 47, 57, 62, 51, 61, 58, 52, 63, 56}; const int b[] = {0, 1, 3, 2, 6, 7, 5, 4}; string bS; int N, K, S, T; vector <int> v, ans; int cnt[262144]; vector <int> build(int N){ if (N == 1){ vector <int> ans = {0, 1}; return ans; } vector <int> a = build(N-1); for (int i = 0; i < (1<<(N-1)); i++){ a.push_back((1<<(N-1))+a[(1<<(N-1))-1-i]); } return a; } vector <int> solve(int N, int K){ v = build(N); ans.clear(); ans.push_back(0); for (int i = 1; i < (1<<N); i++){ ans.push_back(ans[i-1]); for (int j = 0; j < N; j++) if (((v[i]^v[i-1])>>j)&1){ for (int t = 0; t < K; t++) flipbit(ans[i], (j+t)%N); } } memset(cnt, 0, sizeof(cnt)); bool ok = 1; for (int x : ans){ if (cnt[x]){ ok = 0; break; } cnt[x]++; } if (ok){ return ans; } if (K%2 == 0) return {}; if (N == 2*K){ vector <int> tmp = solve(N-2, K), ans(0); for (int i = 0; i < (1<<N); i++){ if (i == 0){ ans.push_back(0); continue; } if (i%4 == 1 || i%4 == 3) ans.push_back(ans.back()^((1<<K)-1)); if (i%4 == 2) ans.push_back(ans.back()^((1<<N)-(1<<K))); if (i%4 == 0){ ans.push_back(ans.back()^(tmp[i/4]<<1)^(tmp[i/4-1]<<1)); } } return ans; } if (K == 3){ vector <int> tmp = solve(N-3, 3), ans = tmp; for (int i = 1; i < 8; i++){ int x = ans.back()&((1<<(N-3))-1); x ^= (1<<(N-4))+(1<<(N-5)); for (int j = 0; j < (1<<(N-3)); j++) ans.push_back((b[i]<<(N-3))+(x^tmp[j])); } return ans; } return {}; } int main(){ // freopen("LYUBOYN.inp", "r", stdin); // freopen("LYUBOYN.out", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> K >> T >> bS; for (int i = 0; i < N; i++) if (bS[i] == '1') S += (1<<(N-1-i)); vector <int> ans = solve(N, K); if (ans.empty()){ cout << "-1\n"; return 0; } cout << (1<<N) << '\n'; for (int &x : ans){ x ^= S; for (int i = N-1; i >= 0; i--) cout << ((x>>i)&1); cout << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...