Source Code
#define F first
#define S second
#define rep(i,a,b) for(int i=a;!(a==b&&i!=b)&&((i<=b&&b>=a)||(i>=b&&a>=b));i+=(a<=b?1:-1))
#define pb push_back
#define Fbitl __builtin_ffs
#define bit1 __builtin_popcount
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
bool visa[(int)1e6] ;
int main() {
	int n , p ;
	cin >> n;
	vi x , y ;
	int res = 0;
	for ( int i = 0 ; i < n ; i++ ) {
		cin >> p ;
		if ( p > 0 ) {
			if(p%2)x.pb(1);
			else x.pb(2);
		}
		else x.pb(0);
		if (i>0&&x[i] == x[i-1])continue;
		y.pb(x[i]);
	}
	for ( int i = 0 ; i < y.size() ; i++ ) {
		if ( (i==0||i==y.size()-1) && y[i] == 0 ) continue;
		if ( y[i] == 0 ) {
			res++;
			continue;
		}
		if ((y.size()-i>2)&&y[i]+y[i+1]==3&&y[i]==y[i+2]) {
			i+=2;
			res++;
		}
	}
	cout << res ;
	return 0;
}
Copy
Teleportation SAAD
GNU G++17
1 ms
256 KB
Wrong Answer