#include <cassert> #include <cstdio> #include <vector> using namespace std; const int kMaxA = 201718; const int kMaxJump = 20; const int kMaxN = 1000000; vector<int> c(kMaxA + kMaxJump + 1); int main() { assert(1 << kMaxJump >= kMaxN); int n; scanf("%d", &n); while (n--) { int a; scanf("%d", &a); ++c[a]; } for (int i = 1; i < c.size(); ++i) { c[i] += c[i - 1] / 2; c[i - 1] %= 2; } int b = c.size() - 1; while (c[b] == 0) --b; printf("%d\n", b); 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 | #include <cassert> #include <cstdio> #include <vector> using namespace std; const int kMaxA = 201718; const int kMaxJump = 20; const int kMaxN = 1000000; vector<int> c(kMaxA + kMaxJump + 1); int main() { assert(1 << kMaxJump >= kMaxN); int n; scanf("%d", &n); while (n--) { int a; scanf("%d", &a); ++c[a]; } for (int i = 1; i < c.size(); ++i) { c[i] += c[i - 1] / 2; c[i - 1] %= 2; } int b = c.size() - 1; while (c[b] == 0) --b; printf("%d\n", b); return 0; } |