#P9727. [EC Final 2022] Aqre
[EC Final 2022] Aqre
题目描述
Given an matrix, you need to fill it with and , such that:
- There cannot be four consecutive horizontal or vertical cells filled with the same number.
- The cells filled with form a connected area. (Two cells are adjacent if they share an edge. A group of cells is said to be connected if for every pair of cells it is possible to find a path connecting the two cells which lies completely within the group, and which only travels from one cell to an adjacent cell in each step.)
Please construct a matrix satisfying the conditions above and has as many s as possible. Output the maximum number of s, and the matrix.
输入格式
The first line contains an integer -- the number of test cases.
For each test case, the first line contains two integers .
It is guaranteed that the sum of over all test cases does not exceed .
输出格式
For each test case, output the maximum number of s in the first line. Then output the matrix in the following lines. If there are multiple solution, output any.
题目大意
【题目描述】
给定一个 矩阵,你需要用 和 填充它,使得满足以下条件:
- 不能有四个连续的水平或垂直单元格填有相同的数字。
- 填有 的单元格形成一个连通区域。(如果它们共享一个边,则两个单元格是相邻的。如果对于每对单元格,可以找到一条完全位于该区域内的连接两个单元格的路径,并且每一步只能从一个单元格移动到相邻的单元格,则一组单元格被称为连通的。)
请构造一个满足上述条件且具有尽可能多的 的矩阵。输出 的最大数量以及该矩阵。
【输入格式】
第一行包含一个整数 ,表示测试用例的数量。
对于每个测试用例,第一行包含两个整数 。
保证所有测试用例中 的总和不超过 。
【输出格式】
对于每个测试用例,输出第一行中 的最大数量。然后在接下来的 行中输出矩阵。如果有多种解决方案,则输出任意一个。
翻译来自于:ChatGPT
3
2 2
3 4
3 8
4
11
11
9
1110
1110
1110
18
11101110
10111011
11011011