Infinite Sequence of Stacks
unknown
c_cpp
2 years ago
989 B
3
Indexable
#include <bits/stdc++.h> #define F first #define S second #define PB push_back #define MP make_pair #define MOD (int) 1e9 + 7 #define all(x) begin(x), end(x) typedef long long ll; using namespace std; template <typename T> // cin >> vector<T> istream &operator>>(istream &istream, vector<T> &v) { for (auto &it : v) cin >> it; return istream; } template <typename T> // cout << vector<T> ostream &operator<<(ostream &ostream, const vector<T> &c) { for (auto &it : c) cout << it << " "; return ostream; } void solve(void) { int n; cin >> n; vector<int> a(n); cin >> a; int prev = 0, ans = 0; for(int i = 0; i < n; i++) { int curr = a[i] + prev; ans += curr % 2; prev = curr / 2; } while(prev != 0) { ans += prev % 2; prev /= 2; } cout << ans << '\n'; } int main() { ios::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
Editor is loading...