問題一覧 > 通常問題

No.1016 Tic-Tac-Toe

レベル : / AI推定難易度 : 1950 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 158
作問者 : maspy / テスター : beet
お気に入りにしたユーザー ProblemId : 4015 / 自分の提出
問題文最終更新日: 2022-04-25 10:43:05
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 242 (順位表) の他の問題:

Problem Statement

$O$ and $X$ are playing a game on a $1\times N$ grid. The game starts with $O$'s turn and proceeds as follows.

  1. $O$ chooses one cell in which no symbol has been written yet, and writes the symbol "o" in it.
  2. $X$ chooses one cell in which no symbol has been written yet, and writes the symbol "x" in it.
  3. Repeat 1 and 2 until symbols have been written in all cells.
After symbols have been written in all cells, $O$ wins if there is a place where the symbol "o" is written in $3$ consecutive cells. Otherwise, $X$ wins.

This game has progressed partway, and the board in progress is given as a string $S$. It is now $O$'s turn. Determine who wins when both players play optimally.

$T$ boards are given, so make the determination for each of them.

Input

$T$
$N_1 \ S_1$
$N_2 \ S_2$
$\vdots$
$N_T \ S_T$
  • $T$ is a positive integer satisfying $1\leqq T\leqq 100$.
  • $N_i$ is a positive integer satisfying $1\leqq N_i\leqq 1000$.
  • $S_i$ is a string of length $N_i$ consisting of the characters o, x, -. o and x represent the symbols written in those cells so far, and - represents a cell in which no symbol has been written yet.
  • It is guaranteed that $S_i$ contains the same number of o and x (hence it is $O$'s turn next).

Output

On the $i$-th line, output the name of the winner (O or X) for the board $S_i$.
Print a newline at the end.

Sample

Sample 1
Input
7
10 xxoo--xxoo
10 oo-ooxxxx-
10 ooxxo--oxx
10 xooo--xx--
6 oooxxx
6 oxoxox
1 -
Output
O
O
X
O
O
X
X

For the $1$st board xxoo--xxoo, if $O$ writes o in the left empty cell, the grid at the end of the game becomes xxoooxxxoo, which satisfies $O$'s winning condition.

For the $2$nd board, if $O$ writes o in the left empty cell, the grid at the end of the game becomes oooooxxxxx. Here o appears in $5$ consecutive cells, and $O$'s winning condition is satisfied in this case as well.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。