Source Code
#include <bits/stdc++.h> 
#define int long long
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define SORT(c) sort(all(c))
#define rSORT(c) sort(rall(c))
#define f first
#define s second
#define pb push_back
#define endl "\n"
using namespace std;
void solve();
int32_t main(){ios::sync_with_stdio(false);cin.tie(0);int t = 1;int i = 1;
    //cin >> t;
    while(t--){//cout<<"_________________________________\n";cout<<"Test case Number: "<<i++<<endl<<endl;
        solve();
    }
}
void solve(){
    int n;cin >> n;
    vector<int> a(n-1);
    for(int i = 0;i<n-1;i++) cin >> a[i];
    int ans = 0;
    int cnt = 0;
    bool d = true;
    for(int i = 0;i<n-1;i++){
        if(a[i] == 0){
            d = false;
        }
        else{
            if(!d)ans++;
            if(i + 1 < n-1 and i > 0 and a[i] % 2 == 0 and a[i+1] != 0 and a[i-1] != 0){
                cnt++;
            }
            else{
                ans += (cnt+1)/2;
                cnt = 0;
            }
            d = true;
        }
    }
    ans += (cnt+1)/2;
    cnt = 0;
    cout  << ans;
}
Copy
Teleportation barakat
GNU G++17
4 ms
888 KB
Wrong Answer