#P7610. [THUPC 2021] 群星连结

[THUPC 2021] 群星连结

Description

Basic Parameters

First, before the game starts, each player must choose exactly nn characters and number them 1,2,3,,n1,2,3,\dots,n.

Each character has some basic parameters:

  1. HP,hpHP,hp:maximum HP, current HP;
  2. MP,mpMP,mp:maximum energy, current energy;
  3. atk,Δatkatk,\Delta_{atk}:base attack, attack bonus;
  4. def,Δdefdef,\Delta_{def}:base defense, defense bonus;

In addition, for convenience, let A=max(atk+Δatk,1)A=\max(atk+\Delta_{atk},1) and D=max(def+Δdef,0)D=\max(def+\Delta_{def},0).

At the start of the game, current HP hphp equals maximum HP HPHP, and current energy mpmp, attack bonus Δatk\Delta_{atk}, and defense bonus Δdef\Delta_{def} are all 00.

HP,MP,atk,defHP,MP,atk,def are given in the input.

Besides, each character has one talent and one skill, described in the Talent section and the Skill section.

Death Check

At any time during the game, if a character’s current HP hphp drops to 00 or below, then that character is considered dead.

Once a character is considered dead, it completely leaves the battlefield. Its HP is fixed at 00, and it cannot regain HP in any way (i.e. it cannot be revived, even if it has Talent — Mind Over Matter; also, it cannot be healed by skills from other allies). It cannot perform normal attacks or cast skills, and it cannot be selected as a priority target, so it cannot be hit by normal attacks either.

In short, it does not participate in the rest of the game in any form. In this problem, all phrases like “all”, “all characters”, etc. do not include dead characters.

When all characters on one side are considered dead, the game ends immediately and the other side wins (if there are still unresolved effects at this moment, none of them will be processed).

Parameter Overflow

At any time during the game, if a character has hp>HPhp>HP, then hphp immediately becomes HPHP.

At any time during the game, if a character has mp>MPmp>MP, then mpmp immediately becomes MPMP.

Priority Target

Before the game starts, each player must specify an attack order for each character.

Specifically, for character ii, you must determine an attack order pi,1,,pi,np_{i,1},\ldots,p_{i,n}, where pi,1,,pi,np_{i,1},\ldots,p_{i,n} is a permutation of 1,,n1,\ldots,n.

At any time during the game, the priority target of character ii is pi,jp_{i,j} if and only if pi,1,,pi,j1p_{i,1},\ldots,p_{i,j-1} are all dead, and pi,jp_{i,j} is not dead.

Normal Attack

A normal attack deals AA damage to the priority target.

A character with Talent — Transcendence will instead deal AA true damage to the priority target. See the Talent section.

A character with Talent — Stellar Power Projection will add true damage to its normal attack. See the Talent section.

Talent

Talents have the following types (the number at the start of each line is the talent type ID, and the parentheses () contain extra parameters):

  1. Talent — I Shut Down: This character’s talent has no effect;
  2. Talent — Flesh and Blood: This character is immune to half of true damage. See the HP Deduction Phase section for details.
    True damage is described in the HP Deduction section
  3. Talent — Stellar Power Projection (x)(x): Each normal attack by this character additionally deals xx true damage;
  4. Talent — Mind Over Matter (x,y)(x,y): After each allied action ends, this character restores xx HP and additionally restores yy energy;
  5. Talent — Transcendence: This character’s normal attack is treated as a true-damage attack; i.e. its normal attack deals no damage, but deals AA true damage;
  6. Talent — Technology Above All (x,y)(x,y): After each normal attack, this character restores xx HP; after each skill cast, this character additionally restores yy energy. Note: if the normal attack or skill cast causes all enemy characters to become dead, then this character will no longer restore HP or energy.

This problem guarantees that all extra talent parameters are positive integers (but they may be 00 in the input; see the Input Format section for details).

Skill

When a character’s energy equals its maximum energy (and the character is selected to cast a skill during the game), it may clear its energy to 00 and cast one skill.

Skills have the following types (the number at the start of each line is the skill type ID, and the parentheses () contain extra parameters):

  1. Skill: Mind Broken! This character’s active skill has no effect. Note: the skill can still be cast, it just has no effect.
  2. Skill: Green Explosion! (x)(x) Deal xx damage to all enemy characters, then reduce the energy of all enemy characters by mpenemy10\left\lfloor\frac{mp_{enemy}}{10}\right\rfloor, where mpenemymp_{enemy} is that enemy character’s current energy (i.e. for each enemy character, if its current energy is mpenemymp_{enemy}, then after this skill it becomes $mp_{enemy}-\left\lfloor\frac{mp_{enemy}}{10}\right\rfloor$). Note: by the rules, enemy characters first take damage and enter the HP Deduction Phase, restoring energy in that phase, and only then have their energy reduced by this skill.
  3. Skill: Sun (zhou) Rise (ji) (dao) Rain (dan)! Deal AA true damage to all enemy characters.
  4. Skill: Heavenly Tower Overlord Severing Sword! (x)(x) Deal $\min\left(\left\lfloor\frac{HP_{enemy}}{10}\right\rfloor,x\times A\right)$ damage to all enemy targets, where HPenemyHP_{enemy} is the target’s maximum HP.
  5. Skill: The Show Begins! (x,y)(x,y) Let the current round be round tt. From the moment this skill is cast until the end of round t+x1t+x-1, at the end of each allied action, all allied characters additionally restore yy energy.
  6. Skill: Heavenly Wolf Devouring Slash! (x)(x) Decrease the priority target’s defense bonus by xx, then deal AA true damage to the priority target.
  7. Skill: Earth (Too) Blue (Void) Azure (Blue) Flash (Flash) Lightning! (x,y)(x,y) Deal AA true damage to the priority target. Also, let the current round be round tt. From the moment this skill is cast until the end of round t+x1t+x-1, decrease all enemy characters’ attack bonus by yy.
  8. Skill: Aurora Bloom! (x,y,z)(x,y,z) Make exactly one allied character (not dead) with the lowest current HP (if multiple, choose the smallest index) restore zz HP. Also, let the current round be round tt. From the moment this skill is cast until the end of round t+x1t+x-1, increase all allied characters’ attack bonus by yy.
  9. Skill: Meteor! (x,y)(x,y) Deal AA damage to all enemy characters. Let the current round be round tt. After this skill deals damage, until the end of round t+x1t+x-1, decrease all enemy characters’ defense bonus by yy. Note: this skill deals damage first, then applies the debuff.
  10. Skill: Elf’s Blessing! (x,y,z)(x,y,z) All allied characters restore zz HP. Let the current round be round tt. From the moment this skill is cast until the end of round t+x1t+x-1, increase all allied characters’ defense bonus by yy.
  11. Skill: Full Power Ultra Full Burst! The End of Samsara! (x)(x) All allied characters’ base attack atkatk and base defense defdef become twice their original values, i.e. 2×atk,2×def2\times atk, 2\times def; for characters not dead, current HP hphp becomes $\max\left(\left\lfloor\frac{HP}2\right\rfloor,hp\right)$, and current energy mpmp becomes $\max\left(\left\lfloor\frac{MP}2\right\rfloor,mp\right)$; let the current round be round tt. From the moment this skill is cast until the end of round t+x1t+x-1, at the end of each allied action, all allied characters additionally restore 11 energy. At the end of round t+x1t+x-1, if the enemy still has any character not dead, then all allied characters are forced to have their HP cleared to 00 and are considered dead. In addition, when this skill is cast, all characters on the field that have this skill (including itself) will have their skill forcibly replaced with skill ID 00, Skill: Mind Broken! (therefore this skill can be cast at most once in the game).

This problem guarantees that all extra skill parameters are positive integers (but they may be 00 in the input; see the Input section for details).

Note: effects of the form “let the current round be tt, then from casting this skill until the end of round t+x1t+x-1, …” can stack.

HP Recovery and Energy Recovery

HP can only be restored through talents and skills.

At the end of each allied action, all allied characters gain 11 energy. Characters with Talent — Mind Over Matter, and characters affected by Skill: The Show Begins! and Skill: Full Power Ultra Full Burst! The End of Samsara!, can gain extra energy.

After an allied character performs a normal attack or casts a skill, that character gains 11 energy. Characters with Talent — Technology Above All gain extra energy after casting a skill.

Note: when casting a skill, first clear all energy, then cast the skill, then increase energy.

In particular, if the skill is Skill: Full Power Ultra Full Burst! The End of Samsara!, then after setting the caster’s $mp=\max\left(mp,\left\lfloor\frac{MP}2\right\rfloor\right)$, increase energy.

When an allied character enters the HP Deduction Phase due to taking damage, that character gains 11 energy (regardless of whether it actually loses HP).

HP deduction is described in the HP Deduction Phase section.

HP Deduction Phase

When a character takes damage or true damage, it immediately enters the HP Deduction Phase (note that even if it takes 00 damage, it still enters the HP Deduction Phase).

After entering the HP Deduction Phase, according to the energy recovery rules, its energy increases by 11.

Suppose it takes xx damage and yy true damage, then:

  • If it is immune to half of true damage due to Talent — Flesh and Blood, then its HP is reduced by max(xD,0)+yy2\max(x-D,0)+y-\left\lfloor\frac y2\right\rfloor.
  • Otherwise, its HP is reduced by max(xD,0)+y\max(x-D,0)+y.

Game Process

After the game starts, it can be viewed as several rounds, numbered starting from 11.

Each round can be divided into the following 55 phases: Alice’s action (during), end of Alice’s action, Bob’s action (during), end of Bob’s action, end of the current round.

During an allied action,

  1. If there exists at least one allied character that can cast a skill, then choose one to cast a skill in decreasing order of skill ID. If multiple characters can cast the same highest-ID skill, choose the character with the largest character index among them to cast the skill.
  2. If no allied character can cast a skill, then choose one character whose priority target currently has the highest HP to perform a normal attack. If multiple characters have priority targets with the highest HP, choose the character that would deduct more HP from its priority target (not the one that would deal more damage). If there are still multiple choices, choose the one with the largest character index to perform a normal attack.

Then the allied action ends.

Note: during an allied action, you can only choose one character to cast a skill, or choose one character to perform a normal attack.

Input Format

The first line contains a positive integer nn, meaning Alice and Bob each have nn characters.

The next 4n4n lines describe Alice’s character ii from line 4i34i-3 to line 4i4i.

In these four lines:

  • Line 1: four non-negative integers HP,MP,atk,defHP,MP,atk,def, representing the character’s maximum HP, maximum energy, base attack, and base defense, with HP,MP>0HP,MP>0 guaranteed.
  • Line 2: nn positive integers pi,1,pi,2,,pi,np_{i,1},p_{i,2}, \ldots ,p_{i,n}, representing the character’s attack order, guaranteed to be a permutation of 11 to nn.
  • Line 3: three non-negative integers tf,x,ytf,x,y, representing the talent ID and extra parameters. If this talent has fewer than two extra parameters, you may ignore the extra parts (it is guaranteed that these extra parts are 00 in the input).
  • Line 4: four non-negative integers jn,x,y,zjn,x,y,z, representing the skill ID and extra parameters. If this skill has fewer than three extra parameters, you may ignore the extra parts (it is guaranteed that these extra parts are 00 in the input).

The next 4n4n lines describe Bob’s nn characters in the same format.

Output Format

If the game can end with one side winning, then:

  • Line 1: output a positive integer xx, meaning the game ends in round xx.
  • Line 2: output a string (Alice or Bob) indicating the winner.
  • Line 3: output nn non-negative integers, in order, representing each of the winner’s characters’ hphp at the end of the game; output 00 if the character is dead.

If the game will never end or the two sides draw, output any cute emoticon.

3
2 8 1 1
1 2 3
3 1 1
7 2 1 2
6 6 3 0
1 2 3
5 1 1
7 2 1 1
99 10 1 1
2 1 3
1 0 0
10 10 0 0
9 10 1 0
1 2 3
2 1 0
8 2 1 0
8 7 2 1
2 1 3
1 0 0
4 2 1 0
99 10 2 0
2 1 3
1 0 0
10 10 0 0

15
Alice
2 0 96 

Hint

【Constraints】

n10n \le 10, HP,MP,atk>0HP, MP, atk \gt 0, def0def \ge 0.

It is guaranteed that at any time during the game, the absolute value of every parameter and expression mentioned in the statement does not exceed 109{10}^9.

It is guaranteed that the game ends within 2333323333 rounds.

【Source】

From the 2021 Tsinghua University Programming Contest and Collegiate Invitational (THUPC2021).

Resources such as editorials can be found at https://github.com/yylidiw/thupc_2/tree/master.

Translated by ChatGPT 5