CF916B.Jamie and Binary Sequence (changed after round)

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:

Find k integers such that the sum of two to the power of each number equals to the number n and the largest integer in the answer is as small as possible. As there may be multiple answers, you are asked to output the lexicographically largest one.

To be more clear, consider all integer sequence with length k (_a_1, _a_2, ..., a__k) with . Give a value to each sequence. Among all sequence(s) that have the minimum y value, output the one that is the lexicographically largest.

For definitions of powers and lexicographical order see notes.

杰米正在准备一场 Codeforces 比赛。他想出了一个题目,但不知道如何求解。请帮助他写出如下问题的解答:

找出 kk 个整数,使得每个整数作为指数时 22 的幂之和等于给定整数 nn,且所选整数中最大值尽可能小。由于可能存在多个满足条件的答案,你需要输出其中字典序最大的一个。

更准确地说,考虑所有长度为 kk 的整数序列 (a1, a2, ..., ak)(a_1,\,a_2,\,...,\,a_k),满足
。
对每个序列赋予一个值
。
在所有使该值 yy 取得最小值的序列中,输出字典序最大的那个。

关于幂运算与字典序的定义,请参见题末注释。

输入格式

The first line consists of two integers n and k (1 ≤ n ≤ 1018, 1 ≤ k ≤ 105) — the required sum and the length of the sequence.

第一行包含两个整数 nn 和 kk(1 ≤ n ≤ 10181 \leq n \leq 10^{18},1 ≤ k ≤ 1051 \leq k \leq 10^5)——分别为目标和与序列长度。

输出格式

Output "No" (without quotes) in a single line if there does not exist such sequence. Otherwise, output "Yes" (without quotes) in the first line, and k numbers separated by space in the second line — the required sequence.

It is guaranteed that the integers in the answer sequence fit the range [ - 1018, 1018].

如果不存在这样的序列,则在一行中输出“No”(不带引号)。否则,在第一行输出“Yes”(不带引号),在第二行输出 k 个由空格分隔的数字——即所要求的序列。

保证答案序列中的整数均在范围 [ - 10{18},,10{18}] 内。

输入输出样例

  • 输入#1

    23 5

    输出#1

    Yes
    3 3 2 1 0
  • 输入#2

    13 2

    输出#2

    No
  • 输入#3

    1 2

    输出#3

    Yes
    -1 -1

说明/提示

Sample 1:

23 + 23 + 22 + 21 + 20 = 8 + 8 + 4 + 2 + 1 = 23

Answers like (3, 3, 2, 0, 1) or (0, 1, 2, 3, 3) are not lexicographically largest.

Answers like (4, 1, 1, 1, 0) do not have the minimum y value.

Sample 2:

It can be shown there does not exist a sequence with length 2.

Sample 3:

Powers of 2:

If x > 0, then 2_x_ = 2·2·2·...·2 (x times).

If x = 0, then 2_x_ = 1.

If x < 0, then .

Lexicographical order:

Given two different sequences of the same length, (_a_1, _a_2, ... , a__k) and (_b_1, _b_2, ... , b__k), the first one is smaller than the second one for the lexicographical order, if and only if a__i < b__i, for the first i where a__i and b__i differ.

样例 1:

2³ + 2³ + 2² + 2¹ + 2⁰ = 8 + 8 + 4 + 2 + 1 = 23

形如 (3, 3, 2, 0, 1) 或 (0, 1, 2, 3, 3) 的答案不是字典序最大的。

形如 (4, 1, 1, 1, 0) 的答案未取到最小的 y 值。

样例 2:

可以证明,不存在长度为 2 的序列。

样例 3:

2 的幂:

若 x > 0,则 2^x = 2·2·2·...·2(共 x 个因子)。

若 x = 0,则 2^x = 1。

若 x < 0,则 。

字典序:

给定两个长度相同的不等序列 (_a_₁, _a_₂, ... , a__k) 和 (_b_₁, _b_₂, ... , b__k),当且仅当在第一个满足 a__i ≠ b__i 的下标 i 处有 a__i < b__i 时,前者按字典序小于后者。

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

首页