Charlie just downloaded the new free-to-play game Raid: Shadow Legends Conquest. Just what he wanted! In this game, he must defeat enemies, all of which are bots, and restore power to his clan. Both Charlie and the enemy before him start with health points. Then, the two take turns performing actions, with Charlie going first. On each turn, one can perform one of two actions:
A d
Attack your opponent, dealing damage.D d
Dodge your opponent if they attack on the next turn. If they do not attack on the next turn, take damage from self-humility.
Because he is such a computer genius, Charlie has hacked the game and created two lists of actions each representing what the opponent will do and what he will do. Your job is to simulate his battle and find out who wins. If any person's health reaches 0 or below, your program is to output the correct answer and terminate.
Note: Dodging at the end of the list of actions counts as a failed dodge. (i.e. if the enemy prepares a dodge as their last move, they will inflict self-harm.)
Input Specification
The first line of input contains two space separated positive integers and .
The next lines contain an uppercase Latin letter and a non-negative integer representing Charlie's actions.
The next lines contain an uppercase Latin letter and a non-negative integer representing his opponent's actions.
Output Specification
Output VICTORY
if Charlie wins or DEFEAT
if he loses or TIE
if none of them die.
Constraints
Sample Input 1
3 100
A 50
D 10
A 100
A 90
D 0
A 0
Sample Output 1
DEFEAT
Sample Explanation 1
After the first turn, the bot's health is at 50. After the second turn, Charlie's health is at 10. After the third turn, Charlie attempts to dodge the next attack but his opponent also dodges causing Charlie's health to drop to 0. The remaining commands are ignored due to Charlie losing.
Sample Input 2
4 100
D 10
D 20
D 30
D 30
D 10
D 20
D 30
D 40
Sample Output 2
VICTORY
Sample Explanation 2
After the second last turn, Charlie's health is at 10 and his opponent's is at 40. Then, his opponent tries to dodge but Charlie does not attack (because the list of actions has been completed) and his opponent takes 40 damage reducing their health to 0.
Sample Input 3
2 100
A 99
A 99
D 1
A 1
Sample Output 3
TIE
Comments
This problem needs to be rewritten to stipulate that the enemy only inflicts self-harm on the final move if Charlie doesn't die from his own self-damage first. For example:
The way the problem reads, Charlie should take 10 self damage (and die) since the enemy defended on the subsequent move, and the enemy should also take 10 self damage (and die) because he defended on the final move.
It seems like a TIE but the judge appears to consider this a DEFEAT. I understand the problem says "tie if none of them die," but there's a gaping lacuna since the rules as written imply both players can take fatal damage on the final move. They can't. Or, at the very least, Charlie dies first (and loses) in such a scenario.
If you're unhappy about this case, then you should be unhappy about all cases where both players commit to fatal dodging moves for themselves. This "ambiguity" you assert exists cannot simply be exclusive to when this happens on the final turn of the game.
However, the easiest way to resolve this is to interpret the problem statement literally. The damage can only be inflicted on turn - alternatively phrased as you should not preemptively special-case turn dodges as inflicting damage immediately. Therefore, once Charlie's opponent initiates the dodge, Charlie takes fatal damage and loses. Whether it is the final turn is irrelevant.
Note also that if you interpret the statement in this way, then the order in which all damage happens is well-determined. If someone dodges, then on the next turn, either the attack is blocked or the other person dodges and the original person who dodged takes damage. Just because you have the input and you know it's the end doesn't mean that the damage can be inflicted immediately, you have to wait for "Charlie doesn't make an attack" because being allowed to inflict that damage.
I'm struggling with this one. I'm passing all samples as well as the first batch of questions, but in the first question of batch 2 my code outputs DEFEAT and TIE and I'm not seeing where my mistake is.
Is this one of those where each question can have multiple data sets or am I missing something more basic in my code? Would someone be able to provide a sample input where my code fails so I can understand better?
edit: nvm I found my mistake, I did:
Instead of:
what happens if they both knock each other out in the same hit?
You misunderstood the problem statement. They cannot "knock each other out in the same hit".
They alternate turns, for example, first Charlie performs his first move (first move of game), then the bot performs its first move (second move of game), then Charlie performs his second move (third move of game), and so on.
This problem is sponsored by
Raid: Shadow LegendsNord VPN.I really don't understand how sample 3 is a tie.
How I understand it:
Round 1-
Charlie hits for 99 HP damage, enemy sets up dodge.
Charlie HP 100, enemy HP 1
Round 2-
Charlie misses his attack, enemy hits for 1 HP damage
Charlie HP 99, enemy HP 1
Please help me see my error.
TIE if none of them die. They both remain alive so it's a TIE even if one of them has more HP left than the other.
Thank you. This is so obvious now that you've said it.
This one gave me quite a headache. I've managed to mess up order of action, bot attacked first. Then got indices wrong when searching for opponents next move, it goes ziggzaggy if you're working with two lists as I did. And finally the thing, that gave me The most trouble. Only players first move always hits, and only bots last dodge always inflicts self harm.
Why would you intentionally make the explanations vague. What happens when Charlie attacks and enemy defends? Whose points go where? Seriously why do you make simple problems so hard to understand?
Anyway, can anyone explain the logic behind sample 3?
If dodges get carried over to the next turn, then the dodges happen concurrently with the next attacks lined up, yet that contradicts the prompt - which one takes precedence, the 1-turn-delayed dodge or the non-delayed attack? This game design doesn't make sense, and so neither do the sample explanations. GG
In the Sample Explanation 1, it says that "After the third turn, Charlie attempts to dodge the next attack but his opponent also dodges causing Charlie's health to drop to 0". However, in Sample Input 1, in the 3rd round, Charlie dodges and the opponent actually attacks instead of dodging like the explanation said. Shouldn't sample 1 result in a Tie?
I think you just got confused about how the actions actually work, instead of going from 1 row to another it's Charlie's actions first and the Enemie's actions after
so Charlie's actions are:
and the Enemy's actions are:
Lets visualize for a second like a game Charlie - 100 hp Enemy - 100 hp
Move 1 - Charlie attacks enemy for 50 damage
Charlie - 100 hp Enemy - 50 hp
Move 2 - Enemy attacks charlie for 90 damage
Charlie - 10 hp Enemy - 50 hp
Move 3 - Charlie uses dodge which will do 10 damage to him if the enemy doesn't attack him
Charlie - 10 hp Enemy - 50 hp
Move 4 - Enemy uses dodge, Charlie loses 10 hp because of self-humility
Charlie - 0 hp Enemy - 50 hp
Defeat
wow need to watch details on this one....took me 7 days all because my if statement check the health equaling zero instead of less than equal to zero.not so easy to see where mistakes are with pass/fail system... good luck!