#C2599. Valid Sudoku Checker

    ID: 45932 Type: Default 1000ms 256MiB

Valid Sudoku Checker

Valid Sudoku Checker

You are given a 9x9 Sudoku board that is partially filled. A valid Sudoku board must satisfy the following conditions:

  • Each row must contain the digits 1 through 9 at most once (ignoring the character . which represents an empty cell).
  • Each column must contain the digits 1 through 9 at most once (ignoring .).
  • Each of the nine 3x3 sub-grids must contain the digits 1 through 9 at most once (ignoring .).

Formally, if we denote the set of valid digits as \(\{1,2,3,4,5,6,7,8,9\}\), then for every row, column, and 3x3 block, the filled cells must be a subset of \(\{1,2,3,4,5,6,7,8,9\}\) with no duplicates.

The input is provided via stdin as 9 lines, where each line contains 9 space-separated characters (digits or the dot .). Your task is to output True if the board is valid, and False otherwise.

inputFormat

The input consists of 9 lines. Each line contains exactly 9 tokens separated by spaces. Each token is either a digit ('1'-'9') or a dot ('.') representing an empty cell.

Example:

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

outputFormat

Output a single line containing either True or False (without quotes). True indicates the board is valid according to Sudoku rules, while False indicates it is not.

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