#include <iostream> #define MAX_SIZE 2100000 using namespace std; int T[MAX_SIZE]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int N; cin >> N; for (int i = 0; i < MAX_SIZE; i++) { T[i] = 0; } for (int i = 0; i < N; i++) { uint64_t a; cin >> a; T[a]++; } int w = 0; for (int i = 0; i < MAX_SIZE; i++) { if (T[i] >= 2) { T[i + 1] += T[i] / 2; T[i] %= 2; } if (T[i] == 1) { w = i; } } cout << w; 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 39 40 41 42 43 44 45 46 | #include <iostream> #define MAX_SIZE 2100000 using namespace std; int T[MAX_SIZE]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int N; cin >> N; for (int i = 0; i < MAX_SIZE; i++) { T[i] = 0; } for (int i = 0; i < N; i++) { uint64_t a; cin >> a; T[a]++; } int w = 0; for (int i = 0; i < MAX_SIZE; i++) { if (T[i] >= 2) { T[i + 1] += T[i] / 2; T[i] %= 2; } if (T[i] == 1) { w = i; } } cout << w; return 0; } |