Homogeneous Square
Time limit1sMemory limit128 MB
Given an n by n grid, decide whether every choice of n cells with distinct rows and distinct columns has the same sum.
- Level
Medium6 of 10
- Topics
- Math, Matrix, Implementation, Greedy
- Solved
- No attempts yet
Problem
There is a square of size , divided into cells like a checkerboard. Each cell contains a single integer.
Two positions and are independent if they lie in different rows and different columns, that is, and . A set of positions is independent if every pair of them is independent. The number of ways to choose mutually independent positions is exactly (equivalently, pick exactly one cell from each row and one from each column).
The square is called homogeneous if, no matter which independent positions you choose, the sum of the numbers in those cells is always the same.
Given the numbers written in the square, write a program that decides whether the square is homogeneous.
Input
The input consists of several test cases. The first line of each test case contains the size of the square (). The next lines each contain integers separated by spaces. Each number is between and inclusive. The last line of the input contains a single , which is not processed.
Output
For each test case, print homogeneous if the square is homogeneous, and not homogeneous otherwise, each on its own line.