Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- uint64_t rooms_count;
- cin >> rooms_count;
- vector< uint64_t > v(rooms_count);
- for (auto& coeff : v)
- {
- cin >> coeff;
- }
- bool is_first_section_end_found = false;
- uint64_t first_section_end_idx = 0;
- uint64_t result = 0;
- uint64_t tmp = 0;
- for (int i = 0; i < v.size(); ++i) {
- uint64_t coeff = v[i];
- if ((tmp & coeff) == 0)
- {
- tmp |= coeff;
- continue;
- }
- if (!is_first_section_end_found)
- {
- is_first_section_end_found = true;
- first_section_end_idx = i;
- }
- ++result;
- tmp = coeff;
- }
- for (int i = 0; i < first_section_end_idx; ++i) {
- uint64_t coeff = v[i];
- if ((tmp & coeff) == 0)
- {
- tmp |= coeff;
- continue;
- }
- result++;
- break;
- }
- if (result == 0)
- {
- cout << 1;
- }
- else
- {
- cout << result;
- }
- return 0;
- }
- /*
- test1
- 7
- 1 1 2 12 8 6 16
- 2
- test2
- 5
- 1 2 1 2 1
- 3
- test3
- 6
- 1 2 3 4 5 6
- 4
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement