fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n ; cin>>n;
  7. vector<int>arr(n);
  8. for(int i = 0 ; i<n;i++){
  9. cin>>arr[i];
  10. }
  11. int sum = 0 ; int length =1;
  12. for(int i = 0 ; i<n;i++){
  13. int d = arr[i+1]-arr[i];
  14. if((d==0) || (d==1)){
  15. length++;
  16. }
  17. else{
  18. sum+=pow(2,length)-1;
  19. length=1;
  20. }
  21.  
  22. }
  23. cout<<sum;
  24. // your code goes here
  25. return 0;
  26. }
Success #stdin #stdout 0s 5320KB
stdin
6
5 8 8 10 11 12 
stdout
11