CF1453D.Checkpoints

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Gildong is developing a game consisting of nn stages numbered from 11 to nn. The player starts the game from the 11-st stage and should beat the stages in increasing order of the stage number. The player wins the game after beating the nn-th stage.

There is at most one checkpoint on each stage, and there is always a checkpoint on the 11-st stage. At the beginning of the game, only the checkpoint on the 11-st stage is activated, and all other checkpoints are deactivated. When the player gets to the ii-th stage that has a checkpoint, that checkpoint is activated.

For each try of a stage, the player can either beat the stage or fail the stage. If they beat the ii-th stage, the player is moved to the i+1i+1-st stage. If they fail the ii-th stage, the player is moved to the most recent checkpoint they activated, and they have to beat the stages after that checkpoint again.

For example, assume that n=4n = 4 and the checkpoints are on the 11-st and 33-rd stages. The player starts at the 11-st stage. If they fail on the 11-st stage, they need to retry the 11-st stage because the checkpoint on the 11-st stage is the most recent checkpoint they activated. If the player beats the 11-st stage, they're moved to the 22-nd stage. If they fail it, they're sent back to the 11-st stage again. If they beat both the 11-st stage and the 22-nd stage, they get to the 33-rd stage and the checkpoint on the 33-rd stage is activated. Now whenever they fail on the 33-rd stage, or the 44-th stage after beating the 33-rd stage, they're sent back to the 33-rd stage. If they beat both the 33-rd stage and the 44-th stage, they win the game.

Gildong is going to build the stages to have equal difficulty. He wants you to find any series of stages and checkpoints using at most 20002000 stages, where the expected number of tries over all stages is exactly kk, for a player whose probability of beating each stage is exactly 12\cfrac{1}{2}.

吉尔东正在开发一款包含 nn 个关卡的游戏,关卡编号从 11 到 nn。玩家从第 11 关开始游戏,并需按关卡编号递增的顺序依次通关。玩家在成功通关第 nn 关后获胜。

每个关卡上最多设置一个检查点(checkpoint),且第 11 关必定设有检查点。游戏开始时,仅有第 11 关的检查点处于激活状态,其余所有检查点均未激活。当玩家到达第 ii 关且该关设有检查点时,该检查点即被激活。

每次尝试通关某一关时,玩家要么成功通关,要么失败。若玩家成功通关第 ii 关,则进入第 i+1i+1 关;若玩家在第 ii 关失败,则返回至其最近一次激活的检查点所在关卡,并需重新通关该检查点之后的所有关卡。

例如,设 n=4n = 4,且检查点位于第 11 关和第 33 关。玩家起始于第 11 关:

  • 若在第 11 关失败,则因第 11 关是其唯一已激活的检查点,故需重试第 11 关;
  • 若成功通关第 11 关,则进入第 22 关;
  • 若在第 22 关失败,则仍返回至第 11 关重试;
  • 若连续成功通关第 11 关与第 22 关,则抵达第 33 关,此时第 33 关的检查点被激活;
  • 此后,若在第 33 关失败,或在通关第 33 关后于第 44 关失败,均将返回至第 33 关;
  • 若连续成功通关第 33 关与第 44 关,则游戏胜利。

吉尔东计划将所有关卡设计为难度相同。他希望你构造一组关卡及检查点配置(关卡总数不超过 20002000),使得对于每关通关概率恰好为 12\cfrac{1}{2} 的玩家,其在整个游戏中所有关卡的尝试次数的期望值(期望值)恰好等于 kk。

输入格式

Each test contains one or more test cases. The first line contains the number of test cases tt (1≤t≤501 \le t \le 50).

Each test case contains exactly one line. The line consists of a single integer kk (1≤k≤10181 \le k \le 10^{18}) — the expected number of tries over all stages Gildong wants to set for a player whose probability of beating each stage is exactly 12\cfrac{1}{2}.

每个测试包含一个或多个测试用例。第一行包含测试用例的数量 tt(1≤t≤501 \le t \le 50)。

每个测试用例恰好包含一行。该行包含一个整数 kk(1≤k≤10181 \le k \le 10^{18})——即吉隆希望为一名每关通关概率恰好为 12\cfrac{1}{2} 的玩家所设定的、所有关卡的期望尝试次数总和。

输出格式

For each test case, print −1-1 if it's impossible to construct such a series of stages and checkpoints using at most 20002000 stages.

Otherwise, print two lines. The first line should contain a single integer nn (1≤n≤20001 \le n \le 2000) – the number of stages. The second line should contain nn integers, where the ii-th integer represents whether the ii-th stage has a checkpoint. The ii-th integer should be 00 if the ii-th stage doesn't have a checkpoint, and 11 if it has a checkpoint. Note that the first integer must be 11 according to the description.

对于每个测试用例,如果无法使用至多 20002000 个关卡构造出满足要求的关卡与检查点序列,则输出 −1-1。

否则,输出两行。第一行应包含一个整数 nn(1≤n≤20001 \le n \le 2000),表示关卡数量。第二行应包含 nn 个整数,其中第 ii 个整数表示第 ii 个关卡是否设有检查点:若第 ii 个关卡没有检查点,则该整数为 00;若有检查点,则为 11。注意,根据题意,第一个整数必须为 11。

输入输出样例

  • 输入#1

    4
    1
    2
    8
    12

    输出#1

    -1
    1
    1
    4
    1 1 1 1
    5
    1 1 0 1 1

说明/提示

In the first and the second case, we can see that the 'easiest' series of stages is to have 11 stage with a checkpoint. This already requires 22 tries in expectation, so it is impossible to make it to require only 11 try.

In the third case, it takes 22 tries in expectation to beat each stage, and the player can always retry that stage without falling back to one of the previous stages if they fail it. Therefore the total expected number of tries is 88. Note that there exists an answer with fewer stages, but you are not required to minimize the number of stages used.

在第一种和第二种情况下,我们可以看出,“最简单”的关卡序列是设置 11 个带存档点的关卡。这本身已需要期望 22 次尝试,因此不可能使期望尝试次数仅为 11 次。

在第三种情况下,每一关期望需要 22 次尝试才能通过,且玩家在失败时总能重新挑战该关卡,而无需回退到前面任意一关。因此,总的期望尝试次数为 88。注意,存在使用更少关卡的方案,但你无需最小化所用关卡的数量。

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

首页