// // ska.cpp // // // Created by Michał Buda on 20.11.2017. // #include <stdio.h> const int SIZE = 201750; int main() { int n, m; int* tab = new int[SIZE]; for (int i = 0; i < SIZE; ++i) { tab[i] = 0; } scanf("%i", &n); for (int i = 0; i < n; ++i) { scanf("%i", &m); tab[m] += 1; } int i = 0; int r = 0; int d = 0; int result = 0; while (i < SIZE) { if (d > 0) { tab[i] += d; d = 0; } if (tab[i] > 1) { r = tab[i] % 2; d = tab[i] / 2; tab[i] = r; } if (tab[i] == 1) { result = i; } ++i; } printf("%i", result); delete [] tab; 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 47 48 | // // ska.cpp // // // Created by Michał Buda on 20.11.2017. // #include <stdio.h> const int SIZE = 201750; int main() { int n, m; int* tab = new int[SIZE]; for (int i = 0; i < SIZE; ++i) { tab[i] = 0; } scanf("%i", &n); for (int i = 0; i < n; ++i) { scanf("%i", &m); tab[m] += 1; } int i = 0; int r = 0; int d = 0; int result = 0; while (i < SIZE) { if (d > 0) { tab[i] += d; d = 0; } if (tab[i] > 1) { r = tab[i] % 2; d = tab[i] / 2; tab[i] = r; } if (tab[i] == 1) { result = i; } ++i; } printf("%i", result); delete [] tab; return 0; } |