Advertisement
erek1e

IOI '98 P3 - Party Lamps

Jun 7th, 2022
1,137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int n, c, x;
  8.     cin >> n >> c;
  9.     string should(n, ' ');
  10.     while (cin >> x && x != -1) should[x-1] = '1';
  11.     while (cin >> x && x != -1) should[x-1] = '0';
  12.  
  13.     bool got = false;
  14.     for (int bitmask = 0; bitmask < 16; ++bitmask) {
  15.         int pressed = __builtin_popcount(bitmask);
  16.         if (c < pressed || (c - pressed) % 2) continue;
  17.  
  18.         string s;
  19.         bool works = true;
  20.         for (int i = 0; i < n; ++i) {
  21.             s.push_back('1');
  22.             if (bitmask&1) s.back() = '0'+'1'-s.back();
  23.             if ((bitmask&2) && !(i&1)) s.back() = '0'+'1'-s.back();
  24.             if ((bitmask&4) && (i&1)) s.back() = '0'+'1'-s.back();
  25.             if ((bitmask&8) && !(i%3)) s.back() = '0'+'1'-s.back();
  26.             if (should[i] != ' ' && s.back() != should[i]) works = false;
  27.         }
  28.         if (works) got = true, cout << s << '\n';
  29.     }
  30.     if (!got) cout << "IMPOSSIBLE\n";
  31.     return 0;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement