#include <stdio.h> #include <assert.h> #include <iostream> #include <stdint.h> using namespace std; int main() { int n; cin >> n; assert(1 <= n); assert(n <= 1000000); const size_t r_size = (201738 + 63) / 64; static uint64_t r[r_size] = {0}; for (int i=0; i<n; i++) { int a; cin >> a; assert(0 <= a); assert(a <= 201718); uint64_t carry = 1ULL << (a % 64); unsigned int j; for (j = a / 64; j < r_size; j++) { uint64_t nr = r[j] + carry; if (nr > r[j]) { r[j] = nr; break; } else { r[j] = nr; carry = 1; } } assert(j < r_size); } int R = 0; for (unsigned int j = 0; j < r_size; j++) { if (r[j]) R=j; } uint64_t RR = r[R]; R *= 64; while (RR) { RR >>= 1; R++; } cout << R-1 << 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 47 48 49 50 | #include <stdio.h> #include <assert.h> #include <iostream> #include <stdint.h> using namespace std; int main() { int n; cin >> n; assert(1 <= n); assert(n <= 1000000); const size_t r_size = (201738 + 63) / 64; static uint64_t r[r_size] = {0}; for (int i=0; i<n; i++) { int a; cin >> a; assert(0 <= a); assert(a <= 201718); uint64_t carry = 1ULL << (a % 64); unsigned int j; for (j = a / 64; j < r_size; j++) { uint64_t nr = r[j] + carry; if (nr > r[j]) { r[j] = nr; break; } else { r[j] = nr; carry = 1; } } assert(j < r_size); } int R = 0; for (unsigned int j = 0; j < r_size; j++) { if (r[j]) R=j; } uint64_t RR = r[R]; R *= 64; while (RR) { RR >>= 1; R++; } cout << R-1 << endl; return 0; } |