#include <stdio.h> #include <string.h> #define N 300000 char result[N]; int main(){ int n,p; int max = 0; memset(result,0,sizeof(char) * N); scanf("%d",&n); for(int i = 0; i < n; ++i){ scanf("%d",&p); while(result[p] != 0){ result[p++] = 0; } result[p] = 1; max = max < p ? p : max; } printf("%d\n",max); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <stdio.h> #include <string.h> #define N 300000 char result[N]; int main(){ int n,p; int max = 0; memset(result,0,sizeof(char) * N); scanf("%d",&n); for(int i = 0; i < n; ++i){ scanf("%d",&p); while(result[p] != 0){ result[p++] = 0; } result[p] = 1; max = max < p ? p : max; } printf("%d\n",max); return 0; } |