22. PPNN arrays - solution

/*
An array is ppnn (parity-parity-non-parity-non-parity, i.e. even-even-odd-odd) if at the even positions of the array (0, 2, 4, ...)
there are only even numbers, and at the odd positions of the array (1, 3, 5, ...) only odd numbers.
Write a program that checks, for several arrays that are read, whether they are ppnn arrays.

Input
The numbers n (5≤n≤100) and k (5≤k≤100) are read from standard input, and then, from the next n lines, n
arrays of k elements each, whose values are between 0 and 1000.

Output
For each of the arrays that were read, print yes to standard output if it satisfies the ppnn condition, and no otherwise.

Example
Input
3 5
1 2 3 4 5
2 3 4 5 6
4 7 0 9 2
Output
no
yes
yes
Explanation
In the first array, at position 0, which is even, there is the number 1, which is odd.

In the second array, at the even positions there are the numbers 2, 4 and 6, which are even, and at the odd positions the numbers 3 and 5, which are odd.

In the third array, at the even positions there are the numbers 4, 0 and 2, which are even, and at the odd positions the numbers 7 and 9, which are odd.
*/
#include <iostream>
#include <vector>

using namespace std;

bool isPPNN(const vector<int>& arr) {
    for (int i = 0; i < arr.size(); i++) {
        if (i % 2 == 0) { // Even position
            if (arr[i] % 2 != 0) {
                return false;
            }
        } else { // Odd position
            if (arr[i] % 2 == 0) {
                return false;
            }
        }
    }
    return true;
}

int main() {
    int n, k;
    cin >> n >> k;

    vector<vector<int>> arrays(n, vector<int>(k));

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < k; ++j) {
            cin >> arrays[i][j];
        }
    }

    for (const auto& arr : arrays) {
        if (isPPNN(arr)) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }

    return 0;
}