LCC '25 Contest 1 S1 - Chaotic Curses

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem types

Two witches, A and B, are fighting over a magical potion that can repair their wands, which were damaged from last Halloween. They decide to settle it with a game. They will curse each other's broomsticks using a sequence of commands: F (move forward), L (turn 90 degrees to the left), and R (turn 90 degrees to the right). Note that the L and R commands only change the direction of the broomstick. Because their wands are broken, they cannot control the order of commands and each curse ends up being a random string consisting of N of these 3 characters. The winner is decided by the witch who is farthest (Euclidean distance) from the starting point when the curse is complete.

Input Specification

The first line of input contains N.

The next two lines contain the curses for witch A and witch B, respectively. Each curse is a string of N characters.

Output Specification

Output A if witch A wins, and B if witch B wins. If it is a tie, output TIE.

Constraints

Subtask 1 [20%]

N \leq 10^3

Subtask 2 [80%]

N \leq 5\cdot 10^6

Sample Input 1

15
FLFFRFLFFRFRFLF
FFFFFFRFFFFFFFF

Output for Sample Input 1

B

Explanation of Output for Sample Input 1

Without loss of generality, assume that both witches start facing North. Witch A ends up 4 units North and 3 units West, so she is 5 units from the starting point. Witch B ends up 6 units North and 8 units East, so she is 10 units from the starting point.

Sample Input 2

6
FFLLFR
FLFRRF

Output for Sample Input 2

TIE

Explanation of Output for Sample Input 2

Both witches end up 1 unit away from the starting point.


Comments

There are no comments at the moment.