#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 9×99\times9 grid with the digits 191\sim9 so that the following conditions are satisfied:

  • The digits 191\sim 9 appear exactly once in each row.
  • The digits 191\sim 9 appear exactly once in each column.
  • The grid is divided into 99 subgrids of size 3×33\times3, and the digits 191\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 22 times or more.

The figure shows a Sudoku grid with no errors.

Input Format

Input a 13×1313\times 13 character matrix representing the Sudoku grid, where:

  • The characters -, |, + represent the grid framework, which divides the grid into 99 subgrids of size 3×33\times 3.
  • The character . represents an empty cell.
  • A digit from 191\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.

+---+---+---+
|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 99, the digit 55 appears 22 times, and in the bottom-right subgrid, the digit 55 also appears 22 times.

Sample Explanation #3

In column 22, the digit 22 appears 22 times, and in column 77, the digit 66 appears 22 times.

Constraints

For 100%100\% 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
11 If there is an error, it can always be found by checking only the row constraints. 1111
22 If there is an error, it can always be found by checking only the column constraints. 1212
33 If there is an error, it can always be found by checking only the subgrid constraints. 1313
44 No special property. 1414

Notes

The scoring of this problem follows the original COCI problem setting, with a full score of 5050.

Translated from COCI2023-2024 CONTEST #1 T1 Sudoku.

Translated by ChatGPT 5