danielvitor23

3461 - InterferĂȘncia em Luzes Hexagonais Lights

Aug 3rd, 2023
1,336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. using namespace std;
  5.  
  6. using i64 = long long;
  7.  
  8. const int TARGET = (1 << 10) - 1;
  9. const int INF = 0x3f3f3f3f;
  10.  
  11. int a[10] = {
  12.   (1 << 1) | (1 << 4), // 1
  13.   (1 << 0) | (1 << 4) | (1 << 5) | (1 << 2), // 2
  14.   (1 << 1) | (1 << 5) | (1 << 6) | (1 << 3), // 3
  15.   (1 << 2) | (1 << 6), // 4
  16.   (1 << 0) | (1 << 1) | (1 << 5) | (1 << 7), // 5
  17.   (1 << 1) | (1 << 2) | (1 << 4) | (1 << 6) | (1 << 7) | (1 << 8), // 6
  18.   (1 << 2) | (1 << 3) | (1 << 5) | (1 << 8), // 7
  19.   (1 << 4) | (1 << 5) | (1 << 8) | (1 << 9), // 8
  20.   (1 << 5) | (1 << 6) | (1 << 7) | (1 << 9), // 9
  21.   (1 << 7) | (1 << 8) // 10
  22. };
  23.  
  24. string get(int mask) {
  25.   string s;
  26.  
  27.   for (int i = 0; i < 10; ++i) {
  28.     s += ((mask & (1 << i)) ? "1" : "0");
  29.   }
  30.  
  31.   return s;
  32. }
  33.  
  34. bool cmp(string a, string b) {
  35.   int sz = a.size();
  36.  
  37.   vector<int> aa, bb;
  38.  
  39.   for (int i = 0; i < sz; ++i) {
  40.     if (a[i] == '1') {
  41.       aa.push_back(i + 1);
  42.     }
  43.     if (b[i] == '1') {
  44.       bb.push_back(i + 1);
  45.     }
  46.   }
  47.  
  48.   for (int i = 0; i < aa.size(); ++i) {
  49.     if (aa[i] < bb[i]) return true;
  50.     if (aa[i] > bb[i]) return false;
  51.   }
  52.  
  53.   return false;
  54. }
  55.  
  56. int main() {
  57.   cin.tie(0)->sync_with_stdio(0);
  58.  
  59.   int initialMask = 0;
  60.   for (int i = 0; i < 10; ++i) {
  61.     int x; cin >> x;
  62.     if (x)
  63.       initialMask |= (1 << i);
  64.   }
  65.  
  66.   int answer = INF;
  67.   string strAns;
  68.   for (int mask = 0; mask < (1 << 10); ++mask) {
  69.     int allMasks = initialMask;
  70.  
  71.     for (int i = 0; i < 10; ++i) {
  72.       if (mask & (1 << i)) {
  73.         allMasks ^= a[i];
  74.       }
  75.     }
  76.  
  77.     if (allMasks == TARGET) {
  78.       int qtd = __builtin_popcount(mask);
  79.       if (qtd < answer or (qtd == answer and cmp(get(mask), strAns))) {
  80.         answer = qtd;
  81.         strAns = get(mask);
  82.       }
  83.     }
  84.   }
  85.  
  86.   if (answer != INF) {
  87.     cout << answer << '\n';
  88.     bool first = true;
  89.     vector<int> a;
  90.  
  91.     for (int i = 0; i < 10; ++i) {
  92.       if (strAns[i] == '1') {
  93.         a.push_back(i + 1);
  94.       }
  95.     }
  96.  
  97.     for (int i = 0; i < answer; ++i) {
  98.       cout << a[i] << " \n"[i==answer-1];
  99.     }
  100.   } else {
  101.     cout << "-1\n";
  102.   }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment