#P9903. [COCI 2023/2024 #1] Sudoku
[COCI 2023/2024 #1] Sudoku
Problem Description
Sudoku is a logic puzzle game. The player’s task is to fill a grid with the digits so that the following conditions are satisfied:
- The digits appear exactly once in each row.
- The digits appear exactly once in each column.
- The grid is divided into subgrids of size , and the digits appear exactly once in each subgrid.
You are given an unfinished Sudoku grid. You need to determine whether there is currently an error. A grid has an error if and only if there exists a row, a column, or a subgrid in which at least one digit appears times or more.
The figure shows a Sudoku grid with no errors.

Input Format
Input a character matrix representing the Sudoku grid, where:
- The characters
-,|,+represent the grid framework, which divides the grid into subgrids of size . - The character
.represents an empty cell. - A digit from means that the corresponding cell has already been filled with that digit.
See the samples for the exact format.
Output Format
Output one line with a string: if this grid has an error, output GRESKA, otherwise output OK.
+---+---+---+
|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|
+---+---+---+
OK
+---+---+---+
|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..|
+---+---+---+
GRESKA
+---+---+---+
|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..|
+---+---+---+
GRESKA
Hint
Sample Explanation #1
This grid has no errors, so output OK.
Sample Explanation #2
In column , the digit appears times, and in the bottom-right subgrid, the digit also appears times.
Sample Explanation #3
In column , the digit appears times, and in column , the digit appears times.
Constraints
For of the testdata, the character matrix contains only digits $1\sim9and the characters-, |, +, ., and the positions of -, |, +` are the same as in the sample.
This problem uses bundled tests.
| Subtask | Special Property | Points |
|---|---|---|
| If there is an error, it can always be found by checking only the row constraints. | ||
| If there is an error, it can always be found by checking only the column constraints. | ||
| If there is an error, it can always be found by checking only the subgrid constraints. | ||
| No special property. |
Notes
The scoring of this problem follows the original COCI problem setting, with a full score of .
Translated from COCI2023-2024 CONTEST #1 T1 Sudoku.
Translated by ChatGPT 5