Source Code
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define ll long long
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;
using namespace std;
//using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vi> adjList;
typedef pair<int, pair<int, int>> iii;
typedef vector<unsigned int> vui;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vi vm;
typedef vector<vm> Mat;

void print(vi &arr) {
    cout << sz(arr) << '\n';
    for (int i = 0; i < sz(arr); ++i) cout << arr[i] << ' ';
    cout << endl;
}


int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#else
    //    freopen("outofplace.in", "r", stdin);
    //    freopen("outofplace.out", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    int n; cin >> n; --n;
    vi arr(n);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
        if (arr[i] == 0) continue;
        if (arr[i] & 1) arr[i] = 1;
        else arr[i] = 2;
    }
    vi compressed;
    for (int i = 0; i < n; ++i) {
        int j = i;
        while (j < n && arr[j] == arr[i]) ++j;
        compressed.push_back(arr[i]);
        i = j - 1;
    }

//    print(compressed);

    int m = sz(compressed);
    int ans = 0;
    for (int i = 0; i < m; ++i) {
        if (!compressed[i]) continue;
        int j = i;
        while (j < m && compressed[j] != 0) ++j;
        if (j - i > 1) ans += (j - i + 1) / 2;
        i = j;
    }

    cout << ans << '\n';

    return 0;
}
Copy
Teleportation Luka
GNU G++17
0 ms
596 KB
Wrong Answer