QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 128 MB 満点: 100

#15245. Jigsaw Puzzle

統計

Little Z has recently become obsessed with jigsaw puzzles, but his intelligence is limited, and he is never able to complete a puzzle. The game is as follows: First, Little Z receives some puzzle pieces, and then he tries to rearrange these pieces to form a $4 \times 4$ square. See the figure below. Note that Little Z cannot rotate or flip these pieces.

Figure 1: Picture 1

Figure 2: Picture 2

Little Z receives the pieces shown in Figure 1 and then rearranges them to obtain the square in Figure 2. Since Little Z is too slow, please write a program to help him solve this problem.

Input

The input contains multiple test cases. Please use EOF to terminate.

The first line of each test case contains a single integer $N$, the number of pieces. Then $N$ pieces follow. The first line of each piece contains two integers $r$ and $c$, representing the number of rows and columns of the piece. Then $r$ lines follow, each containing $c$ characters '0' or '1'. '1' indicates that the piece occupies this position, and '0' indicates that this position is empty. It is guaranteed that each piece is a complete piece (i.e., the '1's are connected) and there are no empty rows or columns.

Output

If it is impossible to form a square, output "No solution". If there are multiple solutions, output "Yes, many!". Otherwise, output "Yes, only one!", and then output the $4 \times 4$ matrix $H$, where $H_{ij}$ represents the piece number at position $i, j$. Piece numbers start from 1.

Examples

Input 1

4
2 3
111
101
4 2
01
01
11
01
2 1
1
1
3 2
10
10
11
4
1 4
1111
1 4
1111
1 4
1111
1 4
1111
4
1 4
1111
1 4
1111
1 4
1111
2 3
111
001

Output 1

Yes, only one!
1112
1412
3422
3442
Yes, many!
No solution

Constraints

For 30% of the data, $N < 5$. For 100% of the data, $N \leq 16$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.