Back
Close

Binario Grid Validator

Statement

 Goal

Validate that the given grid is a valid Binario.

Binario, also called Binary Sudoku, is a puzzle where you have to fill a nxn grid with 1s and 0s while satisfying these three guidelines :
1 - For each row and column, half the digits are 1s and the other half are 0s.
2 - For each row and column, there can never be more than two consecutive ones or two consecutive zeros.
3 - No two rows can be identical. No two columns can be identical.

If the grid is valid, output VALID.
If the grid is invalid, output the lowest index to an invalid row or, if all rows are valid, the lowest index to an invalid column. Indexes of rows and columns are zero-based.
Input
Line 1 : An integer n giving the size of the grid (n x n)
Next n lines : The n space separated digits for each row of the grid (starting with row 0)
Output
VALID if the grid is valid, else the lowest index to an invalid row or, if all rows are valid, the lowest index to an invalid column. Indexes of rows and columns are zero-based.
Constraints
6 ≤ n ≤ 14
n is always even.
The grid only contains 1s and 0s. There are neither empty cells nor other characters.
Example
Input
6
1 0 0 1 0 1
0 1 0 1 1 0
1 0 1 0 0 1
0 1 1 0 0 1
1 0 0 1 1 0
0 1 1 0 1 0
Output
VALID

Game modes
Fastest, Shortest

Test cases
Test 1 - Valid Test
Input
6 1 0 0 1 0 1 0 1 0 1 1 0 1 0 1 0 0 1 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0
Output
VALID

Validator 1 - Valid Validator
Input
8 1 1 0 0 1 1 0 0 1 0 0 1 0 0 1 1 0 0 1 0 1 1 0 1 1 1 0 1 0 0 1 0 0 0 1 1 0 1 1 0 0 1 1 0 1 0 0 1 1 1 0 0 1 0 1 0 0 0 1 1 0 1 0 1
Output
VALID

Test 2 - Rule 1 row Test
Input
12 1 1 0 1 0 0 1 0 0 1 1 0 0 0 1 1 0 1 0 0 1 0 1 1 1 1 0 0 1 0 1 1 0 1 0 0 1 0 0 1 0 0 1 0 1 1 0 1 0 1 1 0 1 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 1 0 1 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 0 1 1 0 0 1 0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 1 0 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 0 1 1 0 1 1 0 0 1 1 0 0 1 1 0 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 0 1 0 0 1 1 0 0 1 1 0 1 1 0 0 1 0 0 1 1 0 0 1 0 0 1 1 0 1 1 0 0 1 1 0
Output
4

Validator 6 - Rule 2 column Validator
Input
10 1 1 0 0 1 0 1 0 1 0 1 0 1 1 0 0 1 0 0 1 0 0 1 0 1 1 0 1 0 1 1 1 0 1 0 1 0 1 0 0 1 0 0 1 0 0 1 0 1 1 0 1 1 0 1 1 0 1 0 0 0 1 1 0 1 0 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 1 0 1 1 0 1 0 0 1 1 0 1 0 0 1 1
Output
8

Test 7 - Rule 3 column Test
Input
6 1 1 0 0 1 0 0 1 1 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 0 1 0 0 1 0 1
Output
1

Validator 7 - Rule 3 column Validator
Input
8 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 1 1 1 0 0 1 0 1 0 0 0 1 1 0 1 0 1 1 1 0 1 0 0 1 0 0 0 1 0 1 1 0 1
Output
2

Solution language

Solution

Stub generator input