#P15459. 【MX-X25-T3】『FeOI-5』qjyxfgms

【MX-X25-T3】『FeOI-5』qjyxfgms

Background

"qjyxfgms" is very likely an abbreviation made from the initial letters of Chinese pinyin. A common interpretation is: "请假一下发给秘书" ("qing jia yi xia fa gei mi shu", meaning "Please ask for leave and send it to the secretary".).

Problem Description

You are given a 01 sequence aa of length nn.

You can perform several operations on this sequence. In each operation, you may choose a position i(1≤i≤n−2)i(1\le i\le n-2), and assign ai,ai+1,ai+2a_i,a_{i+1},a_{i+2} to mex({ai,ai+1,ai+2})mex(\{a_i,a_{i+1},a_{i+2}\}).

You need to find the minimum number of operations to make all positions become 00.

Here, mex(S)mex(S) denotes the smallest natural number that does not appear in the set SS.

Input Format

This problem contains multiple test cases.

The first line contains a positive integer TT, denoting the number of test cases. For each test case:

  • The first line contains a positive integer nn.
  • The second line contains nn integers a1,…,ana_1, \ldots, a_n, where ai∈{0,1}a_i\in\{0,1\}.

Output Format

For each test case, output one line with a non-negative integer, representing the answer.

2
6
1 1 0 1 0 1
4
1 1 1 1

3
3

Hint

[Sample Explanation #1]

For the first test case:

  • In the 11st operation, choose position 33. Since mex({a3,a4,a5})=mex({0,1,0})=2mex(\{a_3,a_4,a_5\})=mex(\{0,1,0\})=2, the sequence becomes [1,1,2,2,2,1][1,1,2,2,2,1].
  • In the 22nd operation, choose position 11. Since mex({a1,a2,a3})=mex({1,1,2})=0mex(\{a_1,a_2,a_3\})=mex(\{1,1,2\})=0, the sequence becomes [0,0,0,2,2,1][0,0,0,2,2,1].
  • In the 33rd operation, choose position 44. Since mex({a4,a5,a6})=mex({2,2,1})=0mex(\{a_4,a_5,a_6\})=mex(\{2,2,1\})=0, the sequence becomes [0,0,0,0,0,0][0,0,0,0,0,0].

In total, 33 operations are used to make all positions become 00. It can be proven that no solution with fewer operations exists.

[Constraints]

This problem uses bundled tests.

For all test cases, it is guaranteed that:

  • 1≤T≤1061\le T\le 10^6;
  • 3≤n,∑n≤1063\le n,\sum n\le 10^6;
  • ai∈{0,1}a_i\in\{0,1\}.

::cute-table{tuack}

Subtask ID n≤n\le Special Property Score
11 1515 None 2121
22 10210^2 A 1818
33 10310^3 B 2424
44 10610^6 C 1717
55 None 2020

Special Property A: ∑n3≤3×107\sum n^3\le 3\times 10^7.

Special Property B: ∑n2≤3×107\sum n^2\le 3\times 10^7.

Special Property C: it is guaranteed that the number of positions ii satisfying ai=0a_i=0 does not exceed 1515.

Translated by ChatGPT 5