P9903 [COCI 2023/2024 #1] Sudoku

Description

Sudoku is a logic puzzle game. The player’s task is to fill a $9\times9$ grid with the digits $1\sim9$ so that the following conditions are satisfied: - The digits $1\sim 9$ appear exactly once in each row. - The digits $1\sim 9$ appear exactly once in each column. - The grid is divided into $9$ subgrids of size $3\times3$, and the digits $1\sim 9$ 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 $2$ times or more.** The figure shows a Sudoku grid with no errors. ![](https://cdn.luogu.com.cn/upload/image_hosting/d54z2mz7.png)

Input Format

Input a $13\times 13$ character matrix representing the Sudoku grid, where: - The characters `-`, `|`, `+` represent the grid framework, which divides the grid into $9$ subgrids of size $3\times 3$. - The character `.` represents an empty cell. - A digit from $1\sim9$ 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`.

Explanation/Hint

### Sample Explanation #1 This grid has no errors, so output `OK`. ### Sample Explanation #2 In column $9$, the digit $5$ appears $2$ times, and in the bottom-right subgrid, the digit $5$ also appears $2$ times. ### Sample Explanation #3 In column $2$, the digit $2$ appears $2$ times, and in column $7$, the digit $6$ appears $2$ times. ### Constraints For $100\%$ of the testdata, the character matrix contains only digits $1\sim9` and the characters `-`, `|`, `+`, `.`, and the positions of `-`, `|`, `+` are the same as in the sample. **This problem uses bundled tests.** | Subtask | Special Property | Points | | :----------: | :----------: | :----------: | | $1$ | If there is an error, it can always be found by checking only the row constraints. | $11$ | | $2$ | If there is an error, it can always be found by checking only the column constraints. | $12$ | | $3$ | If there is an error, it can always be found by checking only the subgrid constraints. | $13$ | | $4$ | No special property. | $14$ | ### Notes The scoring of this problem follows the original COCI problem setting, with a full score of $50$. Translated from [COCI2023-2024](https://hsin.hr/coci/archive/2023_2024/) [CONTEST #1](https://hsin.hr/coci/archive/2023_2024/contest1_tasks.pdf) _**T1 Sudoku**_. Translated by ChatGPT 5