Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using ull = int64_t;
- void fastIO() {
- std::ios_base::sync_with_stdio(false);
- std::cin.tie(0);
- std::cout.tie(0);
- }
- int fast_mod(const int input, const int ceil) {
- return input < ceil ? input : input % ceil;
- }
- int main() {
- fastIO();
- int n;
- std::cin >> n;
- std::vector<int> arr(n, 0);
- int countZeroValues = 0;
- for (int i = 0; i < n; i++) {
- std::cin >> arr[i];
- arr[i] = std::abs(arr[i]);
- if (arr[i] == 0) {
- countZeroValues++;
- arr[i] = -1;
- }
- }
- int ans = 0;
- while (countZeroValues != n) {
- for (int i = 0; i < n; i++)
- if (fast_mod(arr[i], 2) == 1 && arr[i] > 0) {
- arr[i] -= 1;
- ans++;
- }
- for (int i = 0; i < n; i++) {
- if (arr[i] > 0)
- arr[i] = arr[i] >> 1;
- if (arr[i] == 0) {
- countZeroValues++;
- arr[i] = -1;
- }
- }
- ans++;
- }
- std::cout << std::max(ans - 1, 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment