#include <iostream> #include <vector> template<class T> T& access(std::vector<T>& v, typename std::vector<T>::size_type i) { if (i >= v.size()) v.resize(i + 1); return v[i]; } int main() { std::ios::sync_with_stdio(false); int n; std::cin >> n; std::vector<int> v; v.reserve(0x32000); while (n--) { int i; std::cin >> i; access(v, i)++; } for (std::vector<int>::size_type i = 0; i < v.size(); i++) { int val = v[i] >> 1; if (val) access(v, i + 1) += val; } std::cout << (v.size() - 1) << '\n'; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include <iostream> #include <vector> template<class T> T& access(std::vector<T>& v, typename std::vector<T>::size_type i) { if (i >= v.size()) v.resize(i + 1); return v[i]; } int main() { std::ios::sync_with_stdio(false); int n; std::cin >> n; std::vector<int> v; v.reserve(0x32000); while (n--) { int i; std::cin >> i; access(v, i)++; } for (std::vector<int>::size_type i = 0; i < v.size(); i++) { int val = v[i] >> 1; if (val) access(v, i + 1) += val; } std::cout << (v.size() - 1) << '\n'; return 0; } |