Two rival mining colonies, Alpha and Beta, are racing to claim plots on a shared 3x3 asteroid survey grid (rows and columns numbered 0 to 2). Colony Alpha stakes the first claim, then the colonies alternate turns, each claiming exactly one previously unclaimed plot per turn, until either one colony claims three plots in a straight line (an entire row, an entire column, or one of the two main diagonals) or every plot on the grid has been claimed. You are given the full sequence of claims made so far, in the order they were made. Determine the current state of the contest.
Line 1: an integer m — the number of claims made so far.
Next m lines: two integers row and col — the plot claimed on that turn, in chronological order. The 1st, 3rd, 5th, ... claims belong to Colony Alpha; the 2nd, 4th, 6th, ... claims belong to Colony Beta.
Print exactly one of the following words:
ALPHA if Colony Alpha has claimed a full row, column, or diagonal.BETA if Colony Beta has claimed a full row, column, or diagonal.DRAW if all 9 plots are claimed and neither colony has completed a line.PENDING if the grid is not yet full and neither colony has completed a line.Example 1
Input
5 0 0 2 0 1 1 2 1 2 2
Expected
ALPHA
Explanation
Claims alternate Alpha, Beta, Alpha, Beta, Alpha: Alpha gets (0,0), (1,1), (2,2); Beta gets (2,0), (2,1). Alpha's three plots form the main diagonal, so Alpha has won.
Example 2
Input
9 0 0 1 1 2 0 1 0 1 2 2 1 0 1 0 2 2 2
Expected
DRAW
Explanation
Alpha (odd claims) gets (0,0), (2,0), (1,2), (0,1), (2,2); Beta (even claims) gets (1,1), (1,0), (2,1), (0,2). All 9 plots end up claimed, and checking every row, column, and diagonal shows no colony completed a line, so the result is a draw.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →