Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int n, c, x;
- cin >> n >> c;
- string should(n, ' ');
- while (cin >> x && x != -1) should[x-1] = '1';
- while (cin >> x && x != -1) should[x-1] = '0';
- bool got = false;
- for (int bitmask = 0; bitmask < 16; ++bitmask) {
- int pressed = __builtin_popcount(bitmask);
- if (c < pressed || (c - pressed) % 2) continue;
- string s;
- bool works = true;
- for (int i = 0; i < n; ++i) {
- s.push_back('1');
- if (bitmask&1) s.back() = '0'+'1'-s.back();
- if ((bitmask&2) && !(i&1)) s.back() = '0'+'1'-s.back();
- if ((bitmask&4) && (i&1)) s.back() = '0'+'1'-s.back();
- if ((bitmask&8) && !(i%3)) s.back() = '0'+'1'-s.back();
- if (should[i] != ' ' && s.back() != should[i]) works = false;
- }
- if (works) got = true, cout << s << '\n';
- }
- if (!got) cout << "IMPOSSIBLE\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement