#include <cmath> #include <cstdio> #define SKA_ENABLED using namespace std; static const int N = 1000000; static const int K = 201718; static const int M = 1 + log(N)/log(2); static const int q[M] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288 }; static int a[K + M + 1]; #ifdef SKA_ENABLED int main() { int n; while(scanf("%d", &n) > 0) { for(int i = 0; i < n; i++) { int u; scanf("%d", &u); a[u]++; } for(int i = 0; i <= K; i++) { const int u = a[i]; for(int j = 0; j < M; j++) { a[i + j] += (bool)(u & q[j]); } a[i] -= u; } int r = K + M; while(a[r] == 0) { r--; } printf("%d\n", r); } return 0; } #endif
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 49 50 51 52 53 54 55 56 57 | #include <cmath> #include <cstdio> #define SKA_ENABLED using namespace std; static const int N = 1000000; static const int K = 201718; static const int M = 1 + log(N)/log(2); static const int q[M] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288 }; static int a[K + M + 1]; #ifdef SKA_ENABLED int main() { int n; while(scanf("%d", &n) > 0) { for(int i = 0; i < n; i++) { int u; scanf("%d", &u); a[u]++; } for(int i = 0; i <= K; i++) { const int u = a[i]; for(int j = 0; j < M; j++) { a[i + j] += (bool)(u & q[j]); } a[i] -= u; } int r = K + M; while(a[r] == 0) { r--; } printf("%d\n", r); } return 0; } #endif |