#include <iostream>
#include <bitset>
std::bitset<2000000> set;
long long max;
void increment(long long x)
{
if(set.test(x)) {
set.reset(x);
increment(x+1);
}
else {
set.set(x);
max = std::max(x, max);
}
}
int main() {
long long n;
std::cin >> n;
max = 0;
for(long long i=0; i<n; i++)
{
long long num;
std::cin >> num;
increment(num);
}
std::cout << max << std::endl;
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 30 31 32 33 | #include <iostream> #include <bitset> std::bitset<2000000> set; long long max; void increment(long long x) { if(set.test(x)) { set.reset(x); increment(x+1); } else { set.set(x); max = std::max(x, max); } } int main() { long long n; std::cin >> n; max = 0; for(long long i=0; i<n; i++) { long long num; std::cin >> num; increment(num); } std::cout << max << std::endl; return 0; } |
English