Advertisement
Josif_tepe

Untitled

Mar 15th, 2021
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <map>
  6. using namespace std;
  7. int main(){
  8.     long long n;
  9.     cin>>n;
  10.     int niza[n];
  11.     for(int i = 0; i < n; i++){
  12.         cin>>niza[i];
  13.     }
  14.     long long sz = 0;
  15.     long long answer = 0;
  16.     long long prev_zero = -1;
  17.     for(int i = 0; i < n; i++) {
  18.         if(niza[i] == 0) {
  19.             answer += (long long)(i - prev_zero) * (long long)(n - i);
  20.             prev_zero = i;
  21.         }
  22.     }
  23.     cout << answer << endl;
  24.  
  25.     return 0;
  26. }
  27.  
  28. /*
  29. 5
  30.  4, 2, 0, 1, 3
  31.  
  32.  **/
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement