#include <cstdio> #include <cstdint> #include <cinttypes> #include <unordered_map> std::unordered_map<uint32_t, uint32_t> values_counts; uint32_t max_value = 0; inline void insert_and_aggregate(uint32_t value) { while (1) { if (value > max_value) { max_value = value; } auto &value_count = values_counts[value]; value_count += 1; if (value_count == 2) { value_count = 0; value = value + 1; } else { break; } } } int main(int argc, char const *argv[]) { uint32_t count; scanf("%" PRIu32, &count); uint32_t value; while (count--) { scanf("%" PRIu32, &value); insert_and_aggregate(value); } printf("%" PRIu32 "\n", max_value); 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 34 35 36 37 38 | #include <cstdio> #include <cstdint> #include <cinttypes> #include <unordered_map> std::unordered_map<uint32_t, uint32_t> values_counts; uint32_t max_value = 0; inline void insert_and_aggregate(uint32_t value) { while (1) { if (value > max_value) { max_value = value; } auto &value_count = values_counts[value]; value_count += 1; if (value_count == 2) { value_count = 0; value = value + 1; } else { break; } } } int main(int argc, char const *argv[]) { uint32_t count; scanf("%" PRIu32, &count); uint32_t value; while (count--) { scanf("%" PRIu32, &value); insert_and_aggregate(value); } printf("%" PRIu32 "\n", max_value); return 0; } |