Advertisement
Derga

Untitled

Sep 29th, 2023 (edited)
880
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. int main() {
  8.     ios_base::sync_with_stdio(false);
  9.     cin.tie(nullptr);
  10.     uint64_t rooms_count;
  11.     cin >> rooms_count;
  12.     vector< uint64_t > v(rooms_count);
  13.     for (auto& coeff : v)
  14.     {
  15.         cin >> coeff;
  16.     }
  17.  
  18.     bool is_first_section_end_found = false;
  19.     uint64_t first_section_end_idx = 0;
  20.     uint64_t result = 0;
  21.     uint64_t tmp = 0;
  22.     for (int i = 0; i < v.size(); ++i) {
  23.         uint64_t coeff = v[i];
  24.         if ((tmp & coeff) == 0)
  25.         {
  26.             tmp |= coeff;
  27.             continue;
  28.         }
  29.         if (!is_first_section_end_found)
  30.         {
  31.             is_first_section_end_found = true;
  32.             first_section_end_idx = i;
  33.         }
  34.         ++result;
  35.         tmp = coeff;
  36.     }
  37.  
  38.     for (int i = 0; i < first_section_end_idx; ++i) {
  39.         uint64_t coeff = v[i];
  40.         if ((tmp & coeff) == 0)
  41.         {
  42.             tmp |= coeff;
  43.             continue;
  44.         }
  45.         result++;
  46.         break;
  47.     }
  48.  
  49.     if (result == 0)
  50.     {
  51.         cout << 1;
  52.     }
  53.     else
  54.     {
  55.         cout << result;
  56.     }
  57.    
  58.     return 0;
  59. }
  60.  
  61. /*
  62. test1
  63. 7
  64. 1 1 2 12 8 6 16
  65.  
  66. 2
  67.  
  68. test2
  69. 5
  70. 1 2 1 2 1
  71.  
  72. 3
  73.  
  74. test3
  75. 6
  76. 1 2 3 4 5 6
  77.  
  78. 4
  79. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement