CF1777A.Everybody Likes Good Arrays!

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

An array aa is good if for all pairs of adjacent elements, aia_i and ai+1a_{i+1} (1≤i<n1\le i \lt n) are of different parity. Note that an array of size 11 is trivially good.

You are given an array of size nn.

In one operation you can select any pair of adjacent elements in which both elements are of the same parity, delete them, and insert their product in the same position.

Find the minimum number of operations to form a good array.

如果对于所有相邻元素对 aia_i 和 ai+1a_{i+1}(其中 1≤i<n1 \le i < n),它们的奇偶性均不同,则称数组 aa 是“好”的。注意:长度为 11 的数组天然就是“好”的。

你被给定一个长度为 nn 的数组。

在一次操作中,你可以任选一对相邻元素,要求这两个元素奇偶性相同;然后删除这两个元素,并在同一位置插入它们的乘积。

求使其变为“好”数组所需的最少操作次数。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤5001 \le t \le 500). The description of the test cases follows.

The first line of each test case contains an integer nn (1≤n≤1001 \le n \le 100).

The second line of each test case contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (1≤ai≤1091 \le a_i \le 10^{9}).

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤5001 \le t \le 500)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1001 \le n \le 100)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(1≤ai≤1091 \le a_i \le 10^{9})。

输出格式

For each test case print an integer, the minimum number of operations required to form a good array.

对于每个测试用例,输出一个整数,表示构造一个“好”数组所需的最少操作次数。

输入输出样例

  • 输入#1

    3
    5
    1 7 11 2 13
    4
    1 2 3 4
    6
    1 1 1 2 2 3

    输出#1

    2
    0
    3

说明/提示

Consider the first test case. Select the 22-nd and the 33-rd integers and apply the operation on them. The array changes from [1,7,11,2,13][1, \color{red}{7}, \color{red}{11}, 2, 13] to [1,77,2,13][1, \color{red}{77}, 2, 13]. Next, select the 11-st and the 22-nd integers, array changes from [1,77,2,13][\color{red}{1}, \color{red}{77}, 2, 13] to [77,2,13][\color{red}{77}, 2, 13]. Thus we require 22 operations. It can be proved that this is the minimum number of operations.

In the second test case, the given array is already good. So we require 00 operations.

考虑第一个测试用例。选择第 22 个和第 33 个整数并对它们执行操作。数组从 [1,7,11,2,13][1, \color{red}{7}, \color{red}{11}, 2, 13] 变为 [1,77,2,13][1, \color{red}{77}, 2, 13]。接下来,选择第 11 个和第 22 个整数,数组从 [1,77,2,13][\color{red}{1}, \color{red}{77}, 2, 13] 变为 [77,2,13][\color{red}{77}, 2, 13]。因此,我们总共需要 22 次操作。可以证明这是所需操作次数的最小值。

在第二个测试用例中,给定的数组已经是“好”的。因此,我们只需要 00 次操作。

输入解题思路,AI测评打分。不知道怎么写?

首页