Sudoku
Time limit1sMemory limit1024 MB
Given a partially filled 9x9 sudoku grid, decide whether any row, column, or 3x3 subgrid repeats a digit.
- Level
Easy2 of 10
- Topics
- Implementation, Matrix
- Solved
- No attempts yet
Problem
Sudoku is a logic-based combinatorial number-placement puzzle. The goal is to fill a grid with the digits 1 to 9 so that the following hold:
- Each row contains each digit from 1 to 9 exactly once.
- Each column contains each digit from 1 to 9 exactly once.
- Each of the nine subgrids contains each digit from 1 to 9 exactly once.
Given a sudoku grid that is not yet finished, determine whether it contains a mistake. You do not need to check whether the grid is solvable.
Input
The input describes the sudoku grid. The characters |, -, and + frame the subgrids. The character . represents an empty cell. All other characters are digits from 1 to 9.
Output
Print GRESKA if the board contains a mistake. Otherwise, print OK.
Hint
In the first example there is no mistake, so the output is OK. In the second example, the digit 5 appears twice in the ninth column, and the digit 5 also appears twice in the lower right subgrid. In the third example, the digit 2 appears twice in the second column and the digit 6 appears twice in the seventh column, so there are two mistakes.