#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <iostream>
#include <cstring>
#include <cctype>
#include <queue>
#include <list>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
typedef long long LL;
typedef pair<int,int> para;
typedef vector<int> VI;
typedef vector<vector<int> > VII;
typedef vector<string> VS;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define FOREACH(a,n) for (__typeof(n.begin())a=n.begin();a!=n.end();++a)
#define FOR(i,a,b) for (int i=(a);i<=(b);++i)
#define FORD(i,a,b) for (int i=(a);i>=(b);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ((int)x.size())
int t[1000007];
int main()
{
int n;
scanf("%d", &n);
REP(i, n) {
scanf("%d", &t[i]);
}
sort(t, t+n);
int p = 0, c = 0;
REP(i, n) {
while (p < t[i]){
c/=2;
p += 1;
}
if (t[i] == p) {
c++;
}
}
while(c > 1){
c /=2;
p+=1;
}
printf("%d\n", p);
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 | #include <cstdio> #include <algorithm> #include <vector> #include <set> #include <map> #include <string> #include <iostream> #include <cstring> #include <cctype> #include <queue> #include <list> #include <cstdlib> #include <cmath> #include <deque> using namespace std; typedef long long LL; typedef pair<int,int> para; typedef vector<int> VI; typedef vector<vector<int> > VII; typedef vector<string> VS; #define PB push_back #define MP make_pair #define F first #define S second #define FOREACH(a,n) for (__typeof(n.begin())a=n.begin();a!=n.end();++a) #define FOR(i,a,b) for (int i=(a);i<=(b);++i) #define FORD(i,a,b) for (int i=(a);i>=(b);--i) #define REP(i,n) for (int i=0;i<(n);++i) #define ALL(x) x.begin(),x.end() #define SIZE(x) ((int)x.size()) int t[1000007]; int main() { int n; scanf("%d", &n); REP(i, n) { scanf("%d", &t[i]); } sort(t, t+n); int p = 0, c = 0; REP(i, n) { while (p < t[i]){ c/=2; p += 1; } if (t[i] == p) { c++; } } while(c > 1){ c /=2; p+=1; } printf("%d\n", p); return 0; } |
English