#include <bits/stdc++.h> using namespace std; #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define st first #define nd second #define pb push_back #define REP(i,a,b) for(int i = (a); i <= (b); i++) #define FOR(i, n) REP(i, 0, int(n) - 1) #define pii pair < int, int > #define ll long long #define fi first #define se second #define mp make_pair #define vi vector <int> const int MAXN = 1000; int tab[1000000]; void add(int a) { while(tab[a] == 1) { tab[a] = 0; a++; } tab[a] = 1; } int main() { ios_base::sync_with_stdio(0); /*REP(i,1,MAXN-1) dp[i][0] = 1; FOR(i,MAXN) dp[0][i] = 0; REP(n,1,MAXN-1) { REP(t,1,MAXN-1) { for(int j=max(0,t-n+1); j<=t; j++) dp[n][t] += dp[n-1][j]; if( (n%4 <=1) && t == n*(n-1)/4 )cout<<n<<" "<<t<<" "<<dp[n][t]<<" "<<dp[n][t] - 1000000000000000000LL<<"\n"; } }*/ int n; cin>>n; FOR(i,n) { int a; cin>>a; add(a); } for(int i=1000000; i>=0; i--) { if(tab[i] == 1) { cout<<i<<"\n"; return 0; } } 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 | #include <bits/stdc++.h> using namespace std; #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define st first #define nd second #define pb push_back #define REP(i,a,b) for(int i = (a); i <= (b); i++) #define FOR(i, n) REP(i, 0, int(n) - 1) #define pii pair < int, int > #define ll long long #define fi first #define se second #define mp make_pair #define vi vector <int> const int MAXN = 1000; int tab[1000000]; void add(int a) { while(tab[a] == 1) { tab[a] = 0; a++; } tab[a] = 1; } int main() { ios_base::sync_with_stdio(0); /*REP(i,1,MAXN-1) dp[i][0] = 1; FOR(i,MAXN) dp[0][i] = 0; REP(n,1,MAXN-1) { REP(t,1,MAXN-1) { for(int j=max(0,t-n+1); j<=t; j++) dp[n][t] += dp[n-1][j]; if( (n%4 <=1) && t == n*(n-1)/4 )cout<<n<<" "<<t<<" "<<dp[n][t]<<" "<<dp[n][t] - 1000000000000000000LL<<"\n"; } }*/ int n; cin>>n; FOR(i,n) { int a; cin>>a; add(a); } for(int i=1000000; i>=0; i--) { if(tab[i] == 1) { cout<<i<<"\n"; return 0; } } return 0; } |