#include <string.h> #include <cstdio> #include <iostream> using namespace std; static const long MAX_A = 201800; static bool ACount[MAX_A+1]; static long N; int main() { long i, result = 0, A; ios_base::sync_with_stdio(false); cin >> N; memset(ACount, 0, sizeof(ACount)); for (i = 0; i < N; ++ i) { cin >> A; while(true) { if (!ACount[A]) { ACount[A] = true; if (A > result) { result = A; } break; } else { ACount[A] = false; ++ A; } } } cout << result << 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 34 35 36 37 38 39 40 41 42 43 44 45 46 | #include <string.h> #include <cstdio> #include <iostream> using namespace std; static const long MAX_A = 201800; static bool ACount[MAX_A+1]; static long N; int main() { long i, result = 0, A; ios_base::sync_with_stdio(false); cin >> N; memset(ACount, 0, sizeof(ACount)); for (i = 0; i < N; ++ i) { cin >> A; while(true) { if (!ACount[A]) { ACount[A] = true; if (A > result) { result = A; } break; } else { ACount[A] = false; ++ A; } } } cout << result << endl; return 0; } |