#C7470. Validating a Sudoku Puzzle

    ID: 51345 Type: Default 1000ms 256MiB

Validating a Sudoku Puzzle

Validating a Sudoku Puzzle

In this problem, you are given a completed 9x9 Sudoku grid. Your task is to determine whether the provided solution is valid.

A valid Sudoku solution must satisfy the following conditions:

  • Each row must contain all digits from \(1\) to \(9\) exactly once, i.e., the set of numbers in each row must be \(\{1,2,\dots,9\}\).
  • Each column must contain all digits from \(1\) to \(9\) exactly once.
  • Each of the nine 3x3 subgrids must also contain all digits from \(1\) to \(9\) exactly once.

You need to output True if the board is valid, and False otherwise.

inputFormat

The input is provided via stdin and consists of exactly 9 lines. Each line contains 9 integers separated by spaces representing a row of the Sudoku grid.

For example:

5 3 4 6 7 8 9 1 2
6 7 2 1 9 5 3 4 8
1 9 8 3 4 2 5 6 7
8 5 9 7 6 1 4 2 3
4 2 6 8 5 3 7 9 1
7 1 3 9 2 4 8 5 6
9 6 1 5 3 7 2 8 4
2 8 7 4 1 9 6 3 5
3 4 5 2 8 6 1 7 9

outputFormat

The output should be printed to stdout. Print True if the Sudoku solution is valid, otherwise print False. There should be no extra output.

## sample
5 3 4 6 7 8 9 1 2
6 7 2 1 9 5 3 4 8
1 9 8 3 4 2 5 6 7
8 5 9 7 6 1 4 2 3
4 2 6 8 5 3 7 9 1
7 1 3 9 2 4 8 5 6
9 6 1 5 3 7 2 8 4
2 8 7 4 1 9 6 3 5
3 4 5 2 8 6 1 7 9
True