#ifdef _MSC_VER #define _CRT_SECURE_NO_WARNINGS #endif #include <stdio.h> #include <string.h> #include <vector> #include <set> #include <map> #include <algorithm> typedef long long int LL; typedef std::vector<int> VI; typedef std::vector<VI> VVI; typedef std::vector<LL> VLL; typedef std::vector<double> VD; typedef std::pair<int, int> PII; typedef std::vector<PII> VPII; static const int INF = 1000000001; static const double EPS = 10e-9; #ifdef _MSC_VER #define VAR(v, n) auto v = (n) #else #define VAR(v, n) __typeof__(n) v = (n) #endif #define FOR(i, b, e) for (int i = (b), _e = (e); i <= _e; ++i) #define FORD(i, b, e) for (int i = (b), _e = (e); i >= _e; --i) #define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i) #define ALL(c) (c).begin(), (c).end() #define SIZE(c) static_cast<int>((c).size()) #define FOREACH(it, c) for (VAR(it, (c).begin()); it != (c).end(); ++it) #define PF push_front #define PB push_back #define MP std::make_pair #define ST first #define ND second #define MAXA 201718 struct Number { static const int SIZE = 2*MAXA; int l; int t[SIZE]; Number(void) : l(0) { REP(i, SIZE) { t[i] = 0; } } void print(void) { printf("b(%d): ", l); FORD(i, l - 1, 0) { printf("%d", t[i]); } } void add(int y, int shift) { int k = 0; int i = 0; while ((i + shift < l) || (y > 0) || (k > 0)) { t[i + shift] += (y & 1) + k; k = t[i + shift] >> 1; t[i + shift] &= 1; y >>= 1; i += 1; } if (i > 0) { l = std::max(l, i + shift); } } int len(void) { return l; } }; int main(void) { int a[MAXA + 1] = { 0x00 }; int b[MAXA + 1] = { 0x00 }; int n = 0; int k = 0; int ignored = scanf("%d", &n); REP(i, n) { int x = 0; ignored = scanf("%d", &x); a[x] += 1; if (a[x] == 1) { b[k++] = x; } } Number sum; REP(i, k) { sum.add(a[b[i]], b[i]); } ignored = printf("%d\n", sum.len() - 1); (void) ignored; 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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | #ifdef _MSC_VER #define _CRT_SECURE_NO_WARNINGS #endif #include <stdio.h> #include <string.h> #include <vector> #include <set> #include <map> #include <algorithm> typedef long long int LL; typedef std::vector<int> VI; typedef std::vector<VI> VVI; typedef std::vector<LL> VLL; typedef std::vector<double> VD; typedef std::pair<int, int> PII; typedef std::vector<PII> VPII; static const int INF = 1000000001; static const double EPS = 10e-9; #ifdef _MSC_VER #define VAR(v, n) auto v = (n) #else #define VAR(v, n) __typeof__(n) v = (n) #endif #define FOR(i, b, e) for (int i = (b), _e = (e); i <= _e; ++i) #define FORD(i, b, e) for (int i = (b), _e = (e); i >= _e; --i) #define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i) #define ALL(c) (c).begin(), (c).end() #define SIZE(c) static_cast<int>((c).size()) #define FOREACH(it, c) for (VAR(it, (c).begin()); it != (c).end(); ++it) #define PF push_front #define PB push_back #define MP std::make_pair #define ST first #define ND second #define MAXA 201718 struct Number { static const int SIZE = 2*MAXA; int l; int t[SIZE]; Number(void) : l(0) { REP(i, SIZE) { t[i] = 0; } } void print(void) { printf("b(%d): ", l); FORD(i, l - 1, 0) { printf("%d", t[i]); } } void add(int y, int shift) { int k = 0; int i = 0; while ((i + shift < l) || (y > 0) || (k > 0)) { t[i + shift] += (y & 1) + k; k = t[i + shift] >> 1; t[i + shift] &= 1; y >>= 1; i += 1; } if (i > 0) { l = std::max(l, i + shift); } } int len(void) { return l; } }; int main(void) { int a[MAXA + 1] = { 0x00 }; int b[MAXA + 1] = { 0x00 }; int n = 0; int k = 0; int ignored = scanf("%d", &n); REP(i, n) { int x = 0; ignored = scanf("%d", &x); a[x] += 1; if (a[x] == 1) { b[k++] = x; } } Number sum; REP(i, k) { sum.add(a[b[i]], b[i]); } ignored = printf("%d\n", sum.len() - 1); (void) ignored; return 0; } |