Problem 1000
Check if Every Row and Column Contains All Numbers
Easy · 10 pts · Matrix, Hash Table
Problem
An N × N matrix is valid if every row and every column contains all the integers from 1 to N. Since each row and column has exactly N cells, this is the same as saying no row or column contains a repeated value or a value outside 1..N. Check each row and each column with a set (or a boolean array of size N) and print YES if the matrix is valid.
Input
The first line contains N. Each of the next N lines contains N integers.
Output
Print YES if every row and column contains all numbers 1 to N, otherwise NO.
Constraints
1 <= N <= 100; 1 <= value <= N
Example input
3 1 2 3 3 1 2 2 3 1
Example output
YES
Explanation
In 1 2 3 / 3 1 2 / 2 3 1, every row and every column contains 1, 2 and 3 exactly once, so the answer is YES.