#P7387. Chess Cannon Duel

    ID: 20583 Type: Default 1000ms 256MiB

Chess Cannon Duel

Chess Cannon Duel

In this game, two players (Red and Black) play on a 1×n board. Initially, every cell is occupied by exactly one cannon. Each cannon belongs either to the Red side or the Black side. Red always moves first. The only move allowed is a capture move with a cannon. A cannon can capture an opponent’s cannon if and only if there is exactly one cannon in the line between them. Formally, if a cannon from the moving player is located at position \(i\) and an opponent’s cannon is at position \(j\) with \(|i-j|=2\) (so that there is exactly one cell between them) and the intermediate cell (at position \((i+j)/2\)) is occupied (by either color), then the moving player may remove the opponent’s cannon from the board and move his cannon into the captured cannon’s cell. (Note that after moves, some cells become empty.)

The game is played in multiple rounds. In each round, the board is given by a string of length \(n\) (cells numbered from \(1\) to \(n\)), where each character is either 'R' (for a Red cannon) or 'B' (for a Black cannon). The two players take turns. On each turn, the current player may choose to perform one valid capture move or to pass. If both players pass consecutively or if no moves are available, the game ends immediately. The winning condition is defined as follows: at the end of the round, if one side has strictly more cannons remaining than the opponent, that side wins the round.

PF, who always plays as Red in every round, wonders whether there is a forced win strategy for him provided that both sides play optimally. You are given \(T\) rounds. For each round, determine if Red (PF) can force a win. Output YES if there is a winning strategy for Red, and NO otherwise.

Note: All formulas are formatted in \(\LaTeX\); e.g. the board dimensions are given as \(1 \times n\) and a valid move requires that \(|i-j| = 2\).

inputFormat

The first line contains an integer \(T\) (the number of rounds). Each of the following \(T\) rounds has two lines: the first line contains an integer \(n\) (the length of the board), and the second line contains a string of length \(n\) consisting only of the characters 'R' and 'B', describing the initial setup of cannons on the board.

outputFormat

For each round, output a single line containing YES if PF (Red) has a forced win strategy under optimal play, or NO otherwise.

sample

3
3
RBR
3
BRB
5
RBRRB
YES

NO YES

</p>