QOJ.ac

QOJ

Límite de tiempo: 2.0 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓

#7030. 奥特曼大战奥德斯拉与波德斯拉

Estadísticas

六个月前,我们的英雄,原名 Huriyyah,击败了这片土地上的所有怪物。现在他改名为奥特曼(Ultraman),离开了这片他深爱的土地,准备迎接新的挑战。

在一个偏远的土地上,当地居民正遭受两只强大而恐怖的怪物:Aodzilla 和 Bodzilla 的骚扰。它们吃掉独自外出的幼童,甚至杀害无辜的人。几十年来,人们一直生活在被攻击的恐惧之中。

为了这些不幸的居民,奥特曼出发前往森林,那里是 Aodzilla 和 Bodzilla 的主要巢穴。在森林里,他面对这两只凶猛残忍的怪物并与它们战斗。Aodzilla 和 Bodzilla 的生命值分别为 $HP_A$ 和 $HP_B$,它们的攻击力分别为 $ATK_A$ 和 $ATK_B$。

他们在洞穴中进行回合制战斗。每一秒,奥特曼首先会受到怪物的攻击,伤害值为所有存活怪物的攻击力之和。然后,他将选择一只仍然存活的怪物进行攻击。被选中的怪物将受到 $i$ 点伤害(即其生命值减少 $i$),其中 $i$ 表示奥特曼从战斗开始到现在总共发起的攻击次数(当前攻击为第 $i$ 次)。

也就是说,在第 1 秒,其中一只怪物会受到 1 点伤害;在第 2 秒,其中一只存活的怪物会受到 2 点伤害;在第 3 秒,其中一只存活的怪物会受到 3 点伤害,以此类推。如果某个时刻怪物的生命值小于或等于零,它会立即死亡。当两只怪物都被消灭时,奥特曼获胜。

现在,请你制定一个策略,使奥特曼在获胜前受到的总伤害最小。策略可以用一个字符串来描述,字符串的长度即为战斗持续的总时间。如果奥特曼在第 $i$ 秒选择攻击 Aodzilla,则字符串的第 $i$ 个字符为 'A';否则,第 $i$ 个字符为 'B',表示该秒的目标是 Bodzilla。你还需要在所有可能的最佳策略中,找到字典序最小的那个策略。

对于两个不同的字符串 $s$ 和 $t$,如果一个字符串是另一个的前缀,则长度较短的字符串在字典序中更小。在其他情况下,如果 $s$ 的第一个字符小于 $t$ 的第一个字符,则 $s$ 在字典序中更小;如果第一个字符相同,则比较第二个字符,以此类推。$t$ 小于 $s$ 的情况定义类似。

输入格式

输入包含多个测试用例,第一行包含一个正整数 $T$,表示测试用例的数量,最多为 $10^5$。

对于每个测试用例,仅一行包含四个整数 $HP_A, HP_B, ATK_A$ 和 $ATK_B$,其中 $1 \le HP_A, HP_B, ATK_A, ATK_B \le 10^9$。

我们保证至多有 100 个测试用例满足 $\max\{HP_A, HP_B\} > 10^3$。

输出格式

对于每个测试用例,输出一行,包含一个整数,表示奥特曼应受到的最小总伤害,以及一个描述最佳策略的字符串,该字符串在所有可能的最佳策略中字典序最小。数字和字符串之间应恰好有一个空格。

样例

输入 1

2
5 15 5 25
5 15 25 5

输出 1

155 BBBBBA
105 AAABBB

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.