Task description:
According to Wikipedia: “Sudoku is a logic-based, combinatorial number-placement puzzle. In classic sudoku, the objective is to fill a 9×9 grid with digits so that each column, each row, and each of the nine 3×3 subgrids that compose the grid (also called ‘boxes’, ‘blocks’, or ‘regions’) contain all of the digits from 1 to 9. The puzzle setter provides a partially completed grid, which for a well-posed puzzle has a single solution.”
The example below illustrates the nine blocks from a completed sudoku puzzle:
132|579|468 498|261|375 756|384|219 ——+——-+—— 643|158|792 521|793|846 987|426|531 ——+——-+—— 214|935|687 365|817|924 879|642|153
Your task is to read a completed sudoku puzzle and check whether it is a valid solution or not. In a valid solution:
- Each line contains all digits from 1 to 9.
- Each column contains all digits from 1 to 9.
- Each block contains all digits from 1 to 9.
Input specification:
The input of a test case contains nine lines, and each line contains nine integers in the range [1,9].
Output specification:
Your program must print a single line as output. Print YES if the input is a valid sudoku solution, and NO
otherwise. Do not forget the new-line character in the end.
Example #1:
|
Input |
Output |
|
132579468 498261375 756384219 643158792 521793846 987426531 214935687 365817924 879642153 |
YES |
Example #2:
|
Input |
Output |
|
312579468 498261375 756384219 643158792 521793846 987426531 214935687 365817924 879642153 |





