/* -*- coding: utf-8 -*- * * 3281.cc: No.3281 Pacific White-sided Dolphin vs Monster - yukicoder */ #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; const int BN = 60; const int D = 4; const int DBN = (BN + D - 1) / D; const int DBITS = 1 << DBN; const int DMSK = DBITS - 1; const long long LINF = 1LL << 62; /* typedef */ using ll = long long; using vl = vector; /* global variables */ int bnums[DBITS]; ll hs[MAX_N]; /* subroutines */ int bitnum(ll n) { int b = 0; for (int i = 0; i < D; i++, n >>= DBN) b += bnums[n & DMSK]; return b; } /* main */ int main() { bnums[0] = 0; for (int bits = 1, msb = 1; bits < DBITS; bits++) { if ((msb << 1) <= bits) msb <<= 1; bnums[bits] = bnums[bits ^ msb] + 1; } int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%lld", hs + i); vl hv(hs, hs + n); int cnt = 0; for (int i = 0; ! hv.empty() && i < BN; i++) { cnt++; ll bi = 1LL << i; vl hv0, hv1; for (auto h: hv) { if ((h & bi) != 0) hv1.push_back(h); else hv0.push_back(h); } if (! hv1.empty()) { int minb = BN + 1; ll minh = LINF; for (auto h: hv1) { int b = bitnum(h); if (minb > b || (minb == b && minh > h)) minb = b, minh = h; } for (auto h: hv1) { if (h == minh) { if (h > bi) hv0.push_back(h - bi); minh = -1; } else hv0.push_back(h + bi); } swap(hv, hv0); //printf(" i=%d:", i); //for (auto h: hv) printf(" %lld", h); putchar('\n'); } } printf("%d\n", cnt + (int)hv.size()); return 0; }