CF1367B.Even Array

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array a[0n1]a[0 \ldots n-1] of length nn which consists of non-negative integers. Note that array indices start from zero.

An array is called good if the parity of each index matches the parity of the element at that index. More formally, an array is good if for all ii ( 0in10 \le i \le n - 1 ) the equality imod2=a[i]mod2i \bmod 2 = a[i] \bmod 2 holds, where xmod2x \bmod 2 is the remainder of dividing xx by 2.

For example, the arrays [ 0,5,2,10, 5, 2, 1 ] and [ 0,17,0,30, 17, 0, 3 ] are good, and the array [ 2,4,6,72, 4, 6, 7 ] is bad, because for i=1i=1 , the parities of ii and a[i]a[i] are different: imod2=1mod2=1i \bmod 2 = 1 \bmod 2 = 1 , but a[i]mod2=4mod2=0a[i] \bmod 2 = 4 \bmod 2 = 0 .

In one move, you can take any two elements of the array and swap them (these elements are not necessarily adjacent).

Find the minimum number of moves in which you can make the array aa good, or say that this is not possible.

输入格式

The first line contains a single integer tt ( 1t10001 \le t \le 1000 ) — the number of test cases in the test. Then tt test cases follow.

Each test case starts with a line containing an integer nn ( 1n401 \le n \le 40 ) — the length of the array aa .

The next line contains nn integers a0,a1,,an1a_0, a_1, \ldots, a_{n-1} ( 0ai10000 \le a_i \le 1000 ) — the initial array.

输出格式

For each test case, output a single integer — the minimum number of moves to make the given array aa good, or -1 if this is not possible.

输入输出样例

  • 输入#1

    4
    4
    3 2 7 6
    3
    3 2 6
    1
    7
    7
    4 9 2 1 18 3 0

    输出#1

    2
    1
    -1
    0

说明/提示

In the first test case, in the first move, you can swap the elements with indices 00 and 11 , and in the second move, you can swap the elements with indices 22 and 33 .

In the second test case, in the first move, you need to swap the elements with indices 00 and 11 .

In the third test case, you cannot make the array good.

首页