Editorial for COCI '23 Contest 1 #1 Sudoku


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Prepared by: Martina Licul

The input data for this problem is not very convenient for solving, but we can reshape it into a more manageable format. A useful representation for solving this problem is to express the Sudoku grid as a matrix of size 9 \times 9, with cells to be filled with numbers.

Now, to determine if there is a mistake in the given 9 \times 9 Sudoku grid, we need to apply the three rules of Sudoku:

Check rows: For each row in the grid, count the number of occurrences of each digit from 1 to 9. If any digit occurs more than once, there is a mistake.

Check columns: Similarly, for each column in the grid, count the number of occurrences of each digit from 1 to 9. If any digit occurs more than once, there is a mistake.

Check 3 \times 3 subgrids: Divide the 9 \times 9 grid into nine 3 \times 3 subgrids. For each subgrid, repeat the process from steps 1 and 2, but instead of rows and columns, check the subgrid.

If none of the checks in steps 1, 2, and 3 found a mistake, that means the board is valid.


Comments

There are no comments at the moment.