CF1675B.Make It Increasing
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Given n integers a1,a2,…,an. You can perform the following operation on them:
- select any element ai (1≤i≤n) and divide it by 2 (round down). In other words, you can replace any selected element ai with the value ⌊2ai⌋ (where ⌊x⌋ is – round down the real number x).
Output the minimum number of operations that must be done for a sequence of integers to become strictly increasing (that is, for the condition a1<a2<⋯<an to be satisfied). Or determine that it is impossible to obtain such a sequence. Note that elements cannot be swapped. The only possible operation is described above.
For example, let n=3 and a sequence of numbers [3,6,5] be given. Then it is enough to perform two operations on it:
- Write the number ⌊26⌋=3 instead of the number a2=6 and get the sequence [3,3,5];
- Then replace a1=3 with ⌊23⌋=1 and get the sequence [1,3,5].
The resulting sequence is strictly increasing because 1<3<5.
给定 n 个整数 a1,a2,…,an。你可以对它们执行以下操作:
- 任选一个元素 ai(其中 1≤i≤n),将其除以 2 并向下取整。换言之,你可以将任意选定的元素 ai 替换为 ⌊2ai⌋(其中 ⌊x⌋ 表示对实数 x 向下取整)。
输出使该整数序列变为严格递增(即满足 a1<a2<⋯<an)所需的最少操作次数;若无法得到这样的序列,则判定为不可能。注意:元素不可交换位置,唯一允许的操作即上述操作。
例如,设 n=3,给定数字序列 [3,6,5]。此时只需执行两次操作即可:
- 将 a2=6 替换为 ⌊26⌋=3,得到序列 [3,3,5];
- 再将 a1=3 替换为 ⌊23⌋=1,得到序列 [1,3,5]。
最终序列严格递增,因为 1<3<5。
输入格式
The first line of the input contains an integer t (1≤t≤104) — the number of test cases in the input.
The descriptions of the test cases follow.
The first line of each test case contains a single integer n (1≤n≤30).
The second line of each test case contains exactly n integers a1,a2,…,an (0≤ai≤2⋅109).
输入的第一行包含一个整数 t(1≤t≤104)—— 表示输入中测试用例的数量。
随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤30)。
每个测试用例的第二行包含恰好 n 个整数 a1,a2,…,an(0≤ai≤2⋅109)。
输出格式
For each test case, print a single number on a separate line — the minimum number of operations to perform on the sequence to make it strictly increasing. If a strictly increasing sequence cannot be obtained, print "-1".
对于每个测试用例,在单独一行中输出一个整数——使该序列严格递增所需的最少操作次数。若无法得到严格递增的序列,则输出 -1。
输入输出样例
输入#1
7 3 3 6 5 4 5 3 2 1 5 1 2 3 4 5 1 1000000000 4 2 8 7 5 5 8 26 5 21 10 2 5 14
输出#1
2 -1 0 0 4 11 0
说明/提示
The first test case is analyzed in the statement.
In the second test case, it is impossible to obtain a strictly increasing sequence.
In the third test case, the sequence is already strictly increasing.
第一个测试用例在题目描述中已进行分析。
第二个测试用例中,无法得到一个严格递增的序列。
第三个测试用例中,该序列本身已经是严格递增的。
输入解题思路,AI测评打分。不知道怎么写?