Source Code
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int cnt[1000000];
int main(){
    ios::sync_with_stdio(0);
    int n;
    cin>>n;
    int ret = 0;
    int cur = 0;
    int first = -1;
    int last = 0;
    for (int i=0;i<n-1;i++) {
        int x;
        cin>>x;
        if (x==0) {
            if (first!=-1) {
                ret+=max(cur - (first%2==0), 0);
            }
            first = -1;
            cur = 0;
        } else {
            if (last==0) ret++;
            if (first==-1)
                first = x;
            if (x%2 && last!=0 && last%2==0) {
                cur++;
            }
        }
        last=x;
    }
    if (first!=-1) {
        ret+=max(cur - (first%2==0), 0);
    }
    cout<<max(0,ret-1)<<endl;
}
Copy
Teleportation RedNextCentury
GNU G++17
26 ms
980 KB
Accepted