Problem list
Log in
#coci00655 · COCI 2023/2024 Contest 1

Sudoku

Silver III 1.0 s 512 MB

Sudoku is a logic-based, combinatorial number-placement puzzle. The objective is to fill a $9 \times 9$ grid with digits from 1 to 9 in such a way that the following statements hold:

  • Each row contains exactly one occurrence of each digit from 1 to 9.
  • Each column contains exactly one occurrence of each digit from 1 to 9.
  • Each of the nine $3 \times 3$ subgrids contains exactly one occurrence of each digit from 1 to 9.

For a given, not yet finished sudoku grid, determine if there is a mistake in it.

Note: it is not necessary to check whether the sudoku grid is solvable.

Input

The input consists of exactly 13 lines of 13 characters each, drawing the $9 \times 9$ grid.

  • The characters |, - and + frame the $3 \times 3$ subgrids: lines 1, 5, 9 and 13 are +---+---+---+, and every other line starts and ends with | and has a | after every third cell.
  • The character . represents an empty cell.
  • Every other character is a digit from 1 to 9.

See the examples for clarification.

Output

Output the word GRESKA if there is a mistake in the sudoku grid. Otherwise, output the word OK.

Example 1

Input
+---+---+---+
|52.|...|.81|
|.39|58.|...|
|.8.|.9.|...|
+---+---+---+
|24.|...|1.3|
|1..|43.|86.|
|.63|..7|.24|
+---+---+---+
|...|1.9|35.|
|..8|.74|6..|
|31.|86.|7.9|
+---+---+---+
Output
OK

Example 2

Input
+---+---+---+
|3..|6..|..4|
|4.9|8.1|..7|
|..7|.49|6..|
+---+---+---+
|946|157|8.2|
|.2.|3..|745|
|.7.|28.|...|
+---+---+---+
|...|4..|..5|
|8.5|.6.|.2.|
|734|..8|5..|
+---+---+---+
Output
GRESKA

Example 3

Input
+---+---+---+
|5..|98.|67.|
|6..|...|.31|
|.2.|613|.4.|
+---+---+---+
|.96|8.2|1.7|
|.28|..5|.9.|
|7.3|19.|6..|
+---+---+---+
|962|.7.|.1.|
|1.5|...|76.|
|.7.|5..|9..|
+---+---+---+
Output
GRESKA

Clarification of the first example: There is no mistake, so the output is OK. Clarification of the second example: There is a mistake in the ninth column: the digit 5 appears twice; and there is also a mistake in the lower right 3 × 3 subgrid: the digit 5 appears twice. Clarification of the third example: There are two mistakes: the digit 2 appears twice in the second column, and the digit 6 appears twice in the seventh column.

Source
COCI 2023/2024 Contest 1
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code