Source Code
   #include<bits/stdc++.h>
    using namespace std;
#define  ll long long
#define Min_Element(a)    (*min_element((a).begin(), (a).end()))
#define Max_Element(a)    (*max_element((a).begin(), (a).end()))
    int main() {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int n;
     cin>>n;
        int x , o=0 ,z=0;
            vector<int>v(n);
        for (int i = 0; i < n; ++i) {
            cin>>v[i];
            if (v[i]==0) z++;
            else o++;
        }
        int ro=0 ,rz=0;
        for (int i = 0; i <n-2 ; ++i) {
            if (v[i]==1 and v[i+1]==v[i] and v[i+2]==v[i]) ro++;
            else if (v[i]==0 and v[i+1]==v[i] and v[i+2]==v[i]) rz++;
        }
        cout<<min(z,o)-min(ro,rz);
    }
Copy
Tha Bits AhmedEzzat
GNU G++17
0 ms
760 KB
Wrong Answer