#B4162. Stable Atom
Stable Atom
Stable Atom
An atom of size n is abstracted as an n×n matrix. Each cell either contains an electron (represented by 1) or is empty (represented by 0). According to τ's theory, an atom is stable if and only if every cell’s four adjacent neighbors (up, down, left, and right) have exactly 2 electrons. In other words, for every cell at position (i,j), if we denote its value by \(b_{i,j}\), then the following must hold:
$$\;b_{i-1,j}+b_{i+1,j}+b_{i,j-1}+b_{i,j+1}=2.$$
You are given T test cases. For each test case, you are given an integer n representing the size of the atom. Your task is to determine whether there exists a stable atom (i.e. a stable electron configuration) of size n. If one exists, output Yes followed by one such configuration (an n×n matrix with each entry either 0 or 1). Otherwise, output No.
inputFormat
The first line contains an integer T, the number of test cases.
Each of the next T lines contains a single integer n — the size of the atom.
outputFormat
For each test case, if a stable configuration exists, output Yes on the first line, followed by n lines with n space-separated integers (each either 0 or 1) representing the configuration. If no stable configuration exists, output No.
sample
2
2
3
Yes
1 1
1 1
No
</p>