## UCC Coding Competition '21 P5 - Woodcutting Game

View as PDF

Points: 10 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem types

After tearing down your pig barn, you and your friend Tyler have to dispose of two long rectangular wooden boards. You have to cut the boards into smaller pieces. Because this is boring, you devise a game to play to make things more interesting.

The two -dimensional rectangular boards have heights of either or and integer widths. For example, one board can be a board, and another can be a board.

You and Tyler will take turns cutting the rectangular boards, and you will go first. Each of the cuts you make must turn one rectangular board into two smaller rectangular boards, each with an integer height and width. The cuts must be made either horizontally or vertically.

In particular, when it is your turn, you have two options as follows. Note that both options leave your opponent with two rectangles, so the game can continue.

Option 1: Choose one board to discard entirely, and then cut the other board into two smaller integer-dimension rectangles however you want.

The below diagram illustrates this option (but does not include all possible ways to cut the rectangle).

Option 2: Choose one board to leave untouched, cut a rectangular piece off the other board, and discard that piece.

If you choose Option , you must EITHER cut off the height OR cut any integer between and (inclusive) off the width of the board that you have chosen to cut.

The below diagram illustrates this option (but does not include all possible ways to cut the rectangle).

You move first. The player who leaves the other player with two boards that can no longer be cut further is declared the winner.

You are deciding whether to place a bet against Tyler, so you want to know whether it is possible for you to guarantee a win, given the starting dimensions of the two boards.

NOTE FOR PYTHON USERS: If your program receives TLE (time limit exceeded), you should try submitting using the PyPy interpreter: when you are submitting your code, try using "PyPy 3" or "PyPy 2" as the language, instead of "Python 3" or "Python 2".

#### Input Specification

The input will be one line, containing four space-separated integers: , , , and , indicating that the two boards you start with are and .

#### Output Specification

Output the character W if you can force a win, or L if your opponent Tyler can force a win.

#### Constraints and Partial Marks

For of the available marks, and .

For another of the available marks, and .

For another of the available marks, and .

For the remaining marks, and .

#### Sample Input 1

2 2 1 3

#### Sample Output 1

W

#### Explanation for Sample Output 1

The sample input indicates that you start with a board and a board.

On your first turn, if you ignore the board, and cut off the width of the board to leave a board (this is permitted in Option 2), Tyler will get a board and a board on his turn.

It is easy to see that no matter how Tyler plays his move, he will leave you with at least one board. As such, on your second turn, you just need to cut a board into two boards, and discard the other board (this is allowed in Option 1). Now, Tyler is left with two boards that cannot be cut further, so he loses, and you win.

Since you are able to force a win, the output is W.

#### Sample Input 2

2 2 1 1

#### Sample Output 2

L

#### Explanation for Sample Output 2

Similar to the example above, if you start with a board and a board, no matter what you do, you will always leave Tyler with at least one board. Tyler can use Option 1 and cut the board into two boards and discard the other board, which is a loss for you.

Since you cannot force a win (instead, Tyler can force you to lose), the output is L.