CF1661B.Getting Zero

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Suppose you have an integer vv. In one operation, you can:

  • either set v=(v+1) mod 32768v = (v + 1) \bmod 32768
  • or set v=(2⋅v) mod 32768v = (2 \cdot v) \bmod 32768.

You are given nn integers a1,a2,…,ana_1, a_2, \dots, a_n. What is the minimum number of operations you need to make each aia_i equal to 00?

假设你有一个整数 vv。在一次操作中,你可以执行以下两种操作之一:

  • 将 vv 设为 (v+1) mod 32768(v + 1) \bmod 32768;
  • 或将 vv 设为 (2⋅v) mod 32768(2 \cdot v) \bmod 32768。

现给你 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n。将每个 aia_i 变为 00 所需的最少操作次数是多少?

输入格式

The first line contains the single integer nn (1≤n≤327681 \le n \le 32768) — the number of integers.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (0≤ai<327680 \le a_i \lt 32768).

第一行包含一个整数 nn(1≤n≤327681 \le n \le 32768)—— 表示整数的个数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(0≤ai<327680 \le a_i \lt 32768)。

输出格式

Print nn integers. The ii-th integer should be equal to the minimum number of operations required to make aia_i equal to 00.

输出 nn 个整数。其中第 ii 个整数应等于将 aia_i 变为 00 所需的最少操作次数。

输入输出样例

  • 输入#1

    4
    19 32764 10240 49

    输出#1

    14 4 4 15

说明/提示

Let's consider each aia_i:

  • a1=19a_1 = 19. You can, firstly, increase it by one to get 2020 and then multiply it by two 1313 times. You'll get 00 in 1+13=141 + 13 = 14 steps.
  • a2=32764a_2 = 32764. You can increase it by one 44 times: 32764→32765→32766→32767→032764 \rightarrow 32765 \rightarrow 32766 \rightarrow 32767 \rightarrow 0.
  • a3=10240a_3 = 10240. You can multiply it by two 44 times: 10240→20480→8192→16384→010240 \rightarrow 20480 \rightarrow 8192 \rightarrow 16384 \rightarrow 0.
  • a4=49a_4 = 49. You can multiply it by two 1515 times.

我们来分别考虑每个 aia_i:

  • a1=19a_1 = 19。你可以首先将其加 11 得到 2020,然后连续乘以 22 共 1313 次,最终得到 00,共需 1+13=141 + 13 = 14 步。
  • a2=32764a_2 = 32764。你可以连续加 11 共 44 次:32764→32765→32766→32767→032764 \rightarrow 32765 \rightarrow 32766 \rightarrow 32767 \rightarrow 0。
  • a3=10240a_3 = 10240。你可以连续乘以 22 共 44 次:10240→20480→8192→16384→010240 \rightarrow 20480 \rightarrow 8192 \rightarrow 16384 \rightarrow 0。
  • a4=49a_4 = 49。你可以连续乘以 22 共 1515 次。

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

首页