AT_arc219_f.Range Division
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a sequence of non-negative integers A=(A1,A2,…,AN) of length N.
You can perform the following operation on A zero or more times. In one operation, perform the following steps in order:
- Choose a pair of integers (l,r) satisfying all of the following conditions:
- 1≤l≤r≤N
- Al,Al+1,…,Ar all have the same parity (that is, they are all even or all odd).
- For each k=l,l+1,…,r, replace Ak with ⌊2Ak⌋.
Find the minimum number of operations needed to make all elements of A equal to 0.
You are given T test cases; solve each of them.
给你一个长度为 N 的非负整数序列 A=(A1,A2,…,AN)。
你可以对 A 执行零次或多次如下操作。每次操作按顺序执行以下步骤:
- 选择一对满足以下所有条件的整数 (l,r):
- 1≤l≤r≤N
- Al,Al+1,…,Ar 具有相同的奇偶性(即全为偶数或全为奇数)。
- 对每个 k=l,l+1,…,r,将 Ak 替换为 ⌊2Ak⌋。
求使 A 的所有元素均变为 0 所需的最少操作次数。
你将得到 T 组测试数据;请分别求解每组数据。
输入格式
The input is given from Standard Input in the following format:
T
case1
case2
⋮
caseT
Each test case is given in the following format:
N
A1 A2 … AN
输入从标准输入中按以下格式给出:
T
case1
case2
⋮
caseT
每个测试用例按以下格式给出:
N
A1 A2 … AN
输出格式
Output the answers for the test cases in order, separated by newlines.
按顺序输出测试用例的答案,答案之间用换行符分隔。
输入输出样例
输入#1
4 2 9 12 3 3 1 2 1 0 7 6 28 24 18 12 22 1
输出#1
5 3 0 10
说明/提示
Sample 1 Explanation:
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.
Constraints
- 1≤T
- 1≤N≤30
- 0≤Ai<260
- The sum of N over all test cases is at most 30.
- All input values are integers.
样例 1 解释:
考虑第一个测试用例。
通过执行如下操作,可在五次操作内将数组 A 的所有元素变为 0:
- 选择 (l,r)=(1,1),此时 A 变为 (4,12)。
- 选择 (l,r)=(1,2),此时 A 变为 (2,6)。
- 选择 (l,r)=(1,2),此时 A 变为 (1,3)。
- 选择 (l,r)=(1,2),此时 A 变为 (0,1)。
- 选择 (l,r)=(2,2),此时 A 变为 (0,0)。
无法用少于五次操作使 A 的所有元素变为 0,因此输出 5。
限制条件
- 1≤T
- 1≤N≤30
- 0≤Ai<260
- 所有测试用例的 N 之和不超过 30。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?