CF2195C.Dice Roll Sequence

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Consider the following cube DD where numbers xx and 7−x7-x lie on opposite sides:

Image generated by Nano Banana Pro.

A sequence bb of integers from 11 to 66 is called a dice roll sequence if it satisfies the following condition:

  • All pairs of adjacent elements lie on adjacent∗^{\text{∗}} sides of the cube.

For example, [1,4,2][1,4,2] is a dice roll sequence, while [3,4,6,3][3,4,6,3] is not because 33 and 44 are not on adjacent sides of the dice. Additionally, [2,2,4][2,2,4] is not a dice roll sequence because 22 and 22 are on the same (not adjacent) side of the dice.

Given a sequence aa of nn integers from 11 to 66, you can perform the following operation any number of times (possibly zero).

  • Select an index 1≤i≤n1 \le i \le n and an integer 1≤x≤61 \le x \le 6. Then, change the value of aia_i to xx.

Please determine the minimum number of operations required to make aa a dice roll sequence.

∗^{\text{∗}}Two sides of the cube SS and TT are called adjacent if they share exactly one edge of the cube. Do note that this condition implies S≠TS \neq T as well.

考虑如下立方体 DD,其中数字 xx 与 7−x7-x 位于立方体的相对面上:

图片由 Nano Banana Pro 生成。

若整数序列 bb 的每个元素均取自 11 至 66,且满足以下条件,则称其为一个骰子滚动序列(dice roll sequence):

  • 所有相邻的两个元素所对应的面在立方体上是相邻的∗^{\text{∗}}。

例如,[1,4,2][1,4,2] 是一个骰子滚动序列;而 [3,4,6,3][3,4,6,3] 不是,因为 33 和 44 在骰子上不处于相邻的面上;此外,[2,2,4][2,2,4] 也不是骰子滚动序列,因为 22 和 22 对应的是立方体上的同一面(而非相邻面)。

给定一个长度为 nn 的整数序列 aa,其中每个元素均取自 11 至 66。你可以执行以下操作任意多次(包括零次):

  • 选择一个下标 1≤i≤n1 \le i \le n 和一个整数 1≤x≤61 \le x \le 6,并将 aia_i 的值修改为 xx。

请确定使 aa 变为骰子滚动序列所需的最少操作次数。

∗^{\text{∗}} 立方体的两个面 SS 与 TT 称为相邻的,当且仅当它们恰好共享立方体的一条棱。注意:该定义隐含了 S≠TS \neq T。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤3⋅1051 \le n \le 3 \cdot 10^5).

The second line of each test case contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (1≤ai≤61 \le a_i \le 6).

It is guaranteed that the sum of nn over all test cases does not exceed 3⋅1053 \cdot 10^5.

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

每个测试用例的第一行包含一个整数 nn(1≤n≤3⋅1051 \le n \le 3 \cdot 10^5)。

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

保证所有测试用例的 nn 值之和不超过 3⋅1053 \cdot 10^5。

输出格式

For each test case, output the minimum number of operations required to make aa a dice roll sequence.

对于每个测试用例,输出使 aa 成为一个骰子序列所需的最少操作次数。

输入输出样例

  • 输入#1

    3
    3
    1 4 2
    4
    3 4 6 3
    10
    6 1 4 3 1 3 2 5 4 4

    输出#1

    0
    1
    4

说明/提示

For the first test case, the sequence aa is [1,4,2][1,4,2]. As this is already a dice roll sequence, the answer is 00.

For the second test case, the sequence aa is [3,4,6,3][3,4,6,3].

Changing exactly one element, you can get [3,5,6,3][3,\color{red}{5},6,3], which is a dice roll sequence.

For the third test case, the sequence aa is [6,1,4,3,1,3,2,5,4,4][6,1,4,3,1,3,2,5,4,4].

Changing exactly 44 elements, you can get [5,1,4,2,1,3,2,1,5,4][\color{red}{5},1,4,\color{red}{2},1,3,2,\color{red}{1},\color{red}{5},4], which is a dice roll sequence.

对于第一个测试用例,序列 aa 为 [1,4,2][1,4,2]。由于它本身已是一个骰子投掷序列,因此答案为 00。

对于第二个测试用例,序列 aa 为 [3,4,6,3][3,4,6,3]。

只需修改恰好一个元素,即可得到 [3,5,6,3][3,\color{red}{5},6,3],这是一个骰子投掷序列。

对于第三个测试用例,序列 aa 为 [6,1,4,3,1,3,2,5,4,4][6,1,4,3,1,3,2,5,4,4]。

只需修改恰好 44 个元素,即可得到 [5,1,4,2,1,3,2,1,5,4][\color{red}{5},1,4,\color{red}{2},1,3,2,\color{red}{1},\color{red}{5},4],这是一个骰子投掷序列。

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

首页