QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 512 MB مجموع النقاط: 100

#5195. Star Connect

الإحصائيات

Background

As everyone knows, the collaboration between Granblue Fantasy and Princess Connect! Re: Dive has arrived! The result of this collaboration is a game called Granblue Connect.

This is a two-player turn-based competitive game, with the two sides denoted as Alice and Bob. The game consists of several rounds, and in each round, the first player and the second player each take one action in sequence.

You, being clever, have written an excellent AI to play this game. This AI follows the game rules and adheres to the strategies defined in the game process entries. However, since you are so strong, you are the only one in the world with this AI, so you can only play against yourself.

Given the initial state of the game, you are to simulate the game process with this AI playing as both Alice and Bob, where Alice goes first. You need to determine whether Alice or Bob wins.

The initial state of the game is provided via input.

Note

In this problem, damage, true damage, and HP deduction are three distinct concepts. Please distinguish between them carefully.

Description

Basic Parameters

Before the game begins, each player must choose exactly $n$ characters, numbered $1, 2, 3, \dots, n$.

Each character has several basic parameters:

  1. $HP, hp$: Maximum HP, current HP.
  2. $MP, mp$: Maximum MP, current MP.
  3. $atk, \Delta_{atk}$: Base attack, attack bonus.
  4. $def, \Delta_{def}$: Base defense, defense bonus.

Additionally, for convenience, we denote $A = \max(atk + \Delta_{atk}, 1)$ and $D = \max(def + \Delta_{def}, 0)$.

At the start of the game, $hp$ is equal to $HP$, while $mp$, $\Delta_{atk}$, and $\Delta_{def}$ are all equal to $0$.

$HP, MP, atk, def$ are provided in the input.

Furthermore, each character possesses one talent and one skill, described in the Talents and Skills sections respectively.

Death Condition

At any moment during the game, if a character's $hp$ drops to $0$ or below, that character is considered [Dead].

Once a character is [Dead], they are completely removed from the field. Their $hp$ is fixed at $0$ and cannot be restored by any means (i.e., they cannot be revived, even with [Talent — Mind Over Matter]; nor can they be healed by other characters' skills). They cannot perform normal attacks, activate skills, or be selected as a priority target, and thus cannot be targeted by normal attacks.

In short, they do not participate in the subsequent game process in any form, and all terms such as "all" or "all characters" in this problem exclude [Dead] characters.

When all characters on one side are [Dead], the game ends immediately, and the other side is declared the winner (if there are any pending resolutions, they are not performed).

Parameter Overflow

At any moment during the game, if a character's $hp > HP$, $hp$ immediately becomes $HP$.

At any moment during the game, if a character's $mp > MP$, $mp$ immediately becomes $MP$.

Priority Target

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

Specifically, for character $i$, an attack order $p_{i,1}, \dots, p_{i,n}$ must be determined, where $p_{i,1}, \dots, p_{i,n}$ is a permutation of $1, \dots, n$.

At any moment during the game, the priority target of character $i$ is $p_{i,j}$ if and only if $p_{i,1}, \dots, p_{i,j-1}$ are all [Dead], and $p_{i,j}$ is not [Dead].

Normal Attack

A normal attack deals $A$ damage to the priority target.

Characters with [Talent — Transcendence] deal $A$ true damage to the priority target instead. See the Talents section for details.

Characters with [Talent — Galaxy Power Projection] deal additional true damage with their normal attacks. See the Talents section for details.

Talents

Talents are of the following types (the number before each line is the talent ID, and parameters in parentheses () are additional parameters):

  • 0 [Talent — Autistic]: This talent has no effect.
  • 1 [Talent — Flesh and Blood]: The character is immune to half of all true damage. See the HP Deduction section for details.
  • 2 [Talent — Galaxy Power Projection] $(x)$: Each normal attack by this character deals an additional $x$ true damage.
  • 3 [Talent — Mind Over Matter] $(x, y)$: After each of the player's actions, this character recovers $x$ HP and additionally recovers $y$ MP.
  • 4 [Talent — Transcendence]: The character's normal attack is treated as true damage; it deals no standard damage but deals $A$ true damage.
  • 5 [Talent — Technology Supremacy] $(x, y)$: After each normal attack, this character recovers $x$ HP; after each skill activation, they additionally recover $y$ MP. Note: If the normal attack or skill causes all enemy characters to become [Dead], this character does not recover HP or MP.

This problem guarantees that all talent parameters are positive integers (though they may be $0$ in the input; see the Input section).

Skills

When a character's $mp$ equals their $MP$ (and it is that character's turn to act), they can reset their $mp$ to $0$ and activate a skill.

Skills are of the following types (the number before each line is the skill ID, and parameters in parentheses () are additional parameters):

  • 0 [Skill: Mental Breakdown!]: The active skill has no effect. Note that it can still be activated, but it does nothing.
  • 1 [Skill: Green Burst!] $(x)$: Deals $x$ damage to all enemy characters, then reduces the $mp$ of all enemy characters by $\lfloor \frac{mp_{enemy}}{10} \rfloor$, where $mp_{enemy}$ is the current $mp$ of the enemy character. Note: According to the rules, enemy characters take damage first, enter the HP deduction phase (where they recover MP), and then have their MP reduced by this skill.
  • 2 [Skill: Rising Rain!]: Deals $A$ true damage to all enemy characters.
  • 3 [Skill: Sky-Shattering Sword!] $(x)$: Deals $\min(\lfloor \frac{HP_{enemy}}{10} \rfloor, x \times A)$ damage to all enemy targets, where $HP_{enemy}$ is the maximum HP of the target.
  • 4 [Skill: Showtime!] $(x, y)$: Let the current round be $t$. From the activation of the skill until the end of round $t+x-1$, all friendly characters additionally recover $y$ MP at the end of the player's action.
  • 5 [Skill: Wolf Bite!] $(x)$: Reduces the priority target's defense bonus by $x$, then deals $A$ true damage to the priority target.
  • 6 [Skill: Blue Lightning!] $(x, y)$: Deals $A$ true damage to the priority target. Additionally, let the current round be $t$. From the activation of the skill until the end of round $t+x-1$, all enemy characters' attack bonuses are reduced by $y$.
  • 7 [Skill: Aurora Bloom!] $(x, y, z)$: Restores $z$ HP to exactly one friendly non-[Dead] character with the lowest HP (if tied, the one with the smallest ID). Additionally, let the current round be $t$. From the activation of the skill until the end of round $t+x-1$, all friendly characters' attack bonuses are increased by $y$.
  • 8 [Skill: Meteor!] $(x, y)$: Deals $A$ damage to all enemy characters. Let the current round be $t$. From after this skill deals damage until the end of round $t+x-1$, all enemy characters' defense bonuses are reduced by $y$. Note: This skill deals damage first, then applies the debuff.
  • 9 [Skill: Spirit Protection!] $(x, y, z)$: Restores $z$ HP to all friendly characters. Let the current round be $t$. From the activation of the skill until the end of round $t+x-1$, all friendly characters' defense bonuses are increased by $y$.
  • 10 [Skill: Full Power! End of Reincarnation!] $(x)$: All friendly characters' base $atk$ and $def$ are doubled ($2 \times atk, 2 \times def$); non-[Dead] characters' $hp$ becomes $\max(\lfloor \frac{HP}{2} \rfloor, hp)$ and $mp$ becomes $\max(\lfloor \frac{MP}{2} \rfloor, mp)$. Let the current round be $t$. From the activation of the skill until the end of round $t+x-1$, all friendly characters additionally recover $1$ MP at the end of the player's action. At the end of round $t+x-1$, if any enemy characters are not [Dead], all friendly characters' $hp$ are set to $0$ and they are marked as [Dead]. Additionally, when this skill is activated, all characters on the field possessing this skill (including the user) have their skill replaced by ID 0 [Skill: Mental Breakdown!] (thus, this skill can be activated at most once per game).

This problem guarantees that all skill parameters are positive integers (though they may be $0$ in the input; see the Input section).

Note: Effects like "Let the current round be $t$, from the activation of the skill until the end of round $t+x-1$..." can stack.

HP and MP Recovery

HP can only be recovered via talents and skills.

At the end of a player's action, all friendly characters' $mp$ increases by $1$. Characters with [Talent — Mind Over Matter] and those affected by [Skill: Showtime!] and [Skill: Full Power! End of Reincarnation!] can recover additional MP.

When a friendly character performs a normal attack or activates a skill, their $mp$ increases by $1$. Characters with [Talent — Technology Supremacy] recover additional MP after activating a skill.

Note: When activating a skill, all $mp$ is consumed first, then the skill is activated, and then $mp$ is increased.

Specifically, if the skill is [Skill: Full Power! End of Reincarnation!], the user's $mp$ becomes $\max(mp, \lfloor \frac{MP}{2} \rfloor)$ before increasing $mp$.

When a friendly character enters the HP deduction phase due to taking damage, their $mp$ increases by $1$ (regardless of whether they actually lose HP).

HP Deduction Phase

When a character takes damage or true damage, they immediately enter the HP deduction phase (note: even if they take $0$ damage, they enter this phase).

Upon entering the HP deduction phase, the character's $mp$ increases by $1$ as per the MP recovery rules.

Suppose they take $x$ damage and $y$ true damage:

  • If the character is immune to half of all true damage due to [Talent — Flesh and Blood], their HP deduction is $\max(x-D, 0) + y - \lfloor \frac{y}{2} \rfloor$.
  • Otherwise, their HP deduction is $\max(x-D, 0) + y$.

Game Process

After the game starts, it proceeds in rounds, starting from round $1$.

Each round is divided into the following $5$ phases: Alice's action (during), Alice's action ends, Bob's action (during), Bob's action ends, and the current round ends.

During a player's action:

  1. If at least one character can activate a skill, choose one to activate the skill, prioritizing the highest skill ID. If multiple characters can activate the same skill ID, choose the one with the largest character ID.
  2. If no character can activate a skill, choose a character to perform a normal attack on their priority target with the highest HP. If multiple characters have priority targets with the same highest HP, choose the character that would cause the most HP deduction (not damage!) to their priority target. If there is still a tie, choose the character with the largest ID.

The player's action then ends.

Note: During a player's action, only one character can be chosen to either activate a skill or perform a normal attack.

Input

The first line contains a positive integer $n$, representing the number of characters for Alice and Bob.

The next $4n$ lines describe Alice's characters $1$ to $n$. For each character:

  • Line 1: $4$ non-negative integers $HP, MP, atk, def$. $HP, MP > 0$.
  • Line 2: $n$ positive integers $p_{i,1}, p_{i,2}, \dots, p_{i,n}$, representing the attack order (a permutation of $1$ to $n$).
  • Line 3: $3$ non-negative integers $tf, x, y$, representing the talent ID and additional parameters. If the talent has fewer than two parameters, the remaining are $0$.
  • Line 4: $4$ non-negative integers $jn, x, y, z$, representing the skill ID and additional parameters. If the skill has fewer than three parameters, the remaining are $0$.

The next $4n$ lines describe Bob's characters in the same format.

Output

If the game ends with one side winning:

  • Line 1: A positive integer $x$, the round number in which the game ended.
  • Line 2: A string (Alice or Bob) indicating the winner.
  • Line 3: $n$ non-negative integers, the $hp$ of each of the winner's characters at the end of the game ($0$ if [Dead]).

If the game never ends or results in a draw, output any cute emoticon.

Examples

Input 1

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

Output 1

15
Alice
2 0 96

Constraints

$n \le 10; HP, MP, atk > 0; def \ge 0$.

It is guaranteed that at any moment during the game, the absolute values of all parameters and expressions mentioned in the problem do not exceed $10^9$.

It is guaranteed that the game ends within $23333$ rounds.

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.