Chocolate Bar Game
Time limit1sMemory limit512 MB
Ruby and Dia alternately eat a fully chocolate prime-sized square (each prime used once) or one single square, and the task is to find the winner under optimal play.
- Level
Hard8 of 10
- Topics
- Game theory, Number theory, Matrix
- Solved
- No attempts yet
Problem
Dia and Ruby take turns playing a game with an square chocolate bar. Ruby goes first. On each turn, the current player must do one of the following:
- Select a prime number that no player has selected in a previous round. Then choose a square on the bar that contains no empty squares (
X), and eat every chocolate square inside it. - Eat any one chocolate square.
The player who eats the last chocolate square wins. Some squares are already eaten at the start. If both players play optimally, who wins? Note: "optimally" means that if a player has a strategy that wins no matter how the opponent responds, that player makes a move that keeps that strategy.
Input
The first line contains a single integer (), the size of the chocolate bar. The next lines each contain characters. Each character is either X (an empty square) or - (a chocolate square).
Output
Print RUBY if Ruby wins, or DIA if Dia wins.