AtCoder Regular Contest-- 219
F
区间除法
Range Division
AtCoder
⌀ 2661
原题
← EG →

区间除法AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

You are given a sequence of non-negative integers $A=(A_1,A_2,\ldots,A_N)$ of length $N$.

给定一个长度为 $N$ 的非负整数序列 $A=(A_1,A_2,\ldots,A_N)$。AI (CI翻译)

You can perform the following operation on $A$ zero or more times. In one operation, perform the following steps in order:

你可以对 $A$ 执行零次或多次以下操作。每次操作按顺序执行以下步骤:AI (CI翻译)

  • Choose a pair of integers $(l,r)$ satisfying all of the following conditions:
  • $1\le l\le r\le N$
    • $A_l,A_{l+1},\ldots,A_r$ all have the same parity (that is, they are all even or all odd).
  • For each $k=l,l+1,\ldots,r$, replace $A_k$ with $\displaystyle\left\lfloor\frac{A_k}2 \right\rfloor$.
  • 选择一对整数 $(l,r)$,满足以下所有条件:
  • $1\le l\le r\le N$
    • $A_l,A_{l+1},\ldots,A_r$ 的奇偶性相同(即它们要么全为偶数,要么全为奇数)。
  • 对每个 $k=l,l+1,\ldots,r$,将 $A_k$ 替换为 $\displaystyle\left\lfloor\frac{A_k}2 \right\rfloor$。
AI (CI翻译)

Find the minimum number of operations needed to make all elements of $A$ equal to $0$.

求使 $A$ 中所有元素都变为 $0$ 所需的最少操作次数。AI (CI翻译)

You are given $T$ test cases; solve each of them.

给定 $T$ 组测试用例,请分别求解。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1\le T$
  • $1\le N\le 30$
  • $0\le A_i< 2^{60}$
  • The sum of $N$ over all test cases is at most $30$.
  • All input values are integers.
  • $1\le T$
  • $1\le N\le 30$
  • $0\le A_i< 2^{60}$
  • 所有测试用例的 $N$ 之和不超过 $30$。
  • 输入的所有数值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入从标准输入按以下格式给出:AI (CI翻译)

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
AI (CI翻译)

Each test case is given in the following format:

每组测试用例按以下格式给出:AI (CI翻译)

N
A_1 A_2 \ldots A_N

N
A_1 A_2 \ldots A_N
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output the answers for the test cases in order, separated by newlines.

按顺序输出各测试用例的答案,每个答案占一行。AI (CI翻译)

样例

Input #1
4
2
9 12
3
3 1 2
1
0
7
6 28 24 18 12 22 1
Output #1
5
3
0
10
Consider the first test case. By performing operations as follows, all elements of $A$ can be made $0$ in five operations: - Choose $(l,r)=(1,1)$. $A$ becomes $(4,12)$. - Choose $(l,r)=(1,2)$. $A$ becomes $(2,6)$. - Choose $(l,r)=(1,2)$. $A$ becomes $(1,3)$. - Choose $(l,r)=(1,2)$. $A$ becomes $(0,1)$. - Choose $(l,r)=(2,2)$. $A$ becomes $(0,0)$. It is impossible to make all elements of $A$ equal to $0$ in fewer than five operations, so output $5$.
题目信息
题号
arc219_f
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。