Source Code
//
//  main.cpp
//  to be better
//
//  Created by Malek Al-Sadi
//
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int n;cin>>n;
    vector<int>v(n+1);
    v[0]=0;
    for(int i(1);i<=n;i++){
        cin>>v[i];
    }
    int cnt(0);
    for(int i(1);i<=n;i++){
        if(v[i]==1){
            if(v[i-1]==0){
                cnt++;
                v[i-1]=1;
            }else if(v[i+1]==0){
                cnt++;
                v[i+1]=1;
                i++;
            }
        }
    }
    cout<<cnt<<endl;
    return 0;
}
Copy
Tha Bits Malek
GNU G++17
0 ms
712 KB
Wrong Answer