CCCHK '08 J4 - Tic-tac-toe

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 64M

Problem type

The game tic-tac-toe is played on a 3 \times 3 grid. Two players place cross (X) and nought (O) alternatively. The game ends whenever a player can make a line of 3 of their mark vertically, horizontally, or diagonally; or all slots are occupied.

O X
X X O
O
Figure 1: A snapshot of a game.

In this problem, you are given a snapshot of a game and you need to verify if it is valid. You can assume that the first mark to be placed is always a cross.

Input Specification

The first input is a number T specifying the number of test cases (1 \le T \le 20\,000). For each test case, 9 characters on each line are used to denote a snapshot, each containing only . (period, representing an empty slot), X, and O. The first 3 characters are the contents of the first row, the next 3 are for the second row, etc. For example, the snapshot of the example is represented as follows:

O.XXXO..O

Output Specification

For each test case, output yes if the snapshot is valid; no, otherwise.

Sample Input

4
.........
..O...X..
..OO..X..
OOOXXX...

Sample Output

yes
yes
no
no

Comments


  • 1
    gj504772  commented on Oct. 8, 2022, 10:31 p.m.

    What does CCCKHK stands for?


    • 3
      d  commented on Oct. 11, 2022, 6:44 a.m.

      Canadian Computing Competition Hong Kong


  • 2
    Phoenix1369  commented on June 24, 2017, 11:30 p.m.

    An error has been discovered in the official test data. The output has been fixed and all submissions have been rejudged. Apologies for any inconvenience caused.


  • 1
    TypicalToxic  commented on June 24, 2017, 8:51 p.m.

    An admin should revisit this problem, 0 solution?


    • 12
      r3mark  commented on June 24, 2017, 10:16 p.m.

      d WA'd, something must be wrong.


  • 2
    Noam527  commented on May 11, 2017, 12:02 p.m.

    I'm pretty sure "valid" as if it's possible to reach this state from the beginning... not that hard to understand


  • 7
    ASentientBot  commented on April 25, 2017, 3:03 p.m.

    Does "valid" just mean that (1) no more than one person has won and (2) there are not more O's than X's?


    • 1
      IanHu  commented on Dec. 17, 2018, 1:41 a.m.

      and also, when "O" is win, number of "X" cannot be greater than "O": "XO. XOX .OX" is invalid


    • 1
      TypicalToxic  commented on May 8, 2017, 3:23 a.m.

      Bump, Clarification on valid?