CF1801A.The Very Beautiful Blanket
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Kirill wants to weave the very beautiful blanket consisting of n×m of the same size square patches of some colors. He matched some non-negative integer to each color. Thus, in our problem, the blanket can be considered a B matrix of size n×m consisting of non-negative integers.
Kirill considers that the blanket is very beautiful, if for each submatrix A of size 4×4 of the matrix B is true:
- A11⊕A12⊕A21⊕A22=A33⊕A34⊕A43⊕A44,
- A13⊕A14⊕A23⊕A24=A31⊕A32⊕A41⊕A42,
where ⊕ means bitwise exclusive OR
Kirill asks you to help her weave a very beautiful blanket, and as colorful as possible!
He gives you two integers n and m.
Your task is to generate a matrix B of size n×m, which corresponds to a very beautiful blanket and in which the number of different numbers maximized.
基里尔想要编织一条极其美丽的毛毯,该毛毯由 n×m 个相同大小的正方形色块组成。他为每种颜色分配了一个非负整数。因此,在本题中,毛毯可视为一个 n×m 的矩阵 B,其元素均为非负整数。
基里尔认为,当且仅当矩阵 B 的每个 4×4 子矩阵 A 均满足以下两个条件时,该毛毯是“极其美丽”的:
- A11⊕A12⊕A21⊕A22=A33⊕A34⊕A43⊕A44,
- A13⊕A14⊕A23⊕A24=A31⊕A32⊕A41⊕A42,
其中 ⊕ 表示按位异或运算。
基里尔请你帮助他编织一条“极其美丽”的毛毯,并且尽可能地丰富多彩!
他给你两个整数 n 和 m。
你的任务是构造一个 n×m 的矩阵 B,使其对应一条“极其美丽”的毛毯,且其中不同数字的个数最大化。
输入格式
The first line of input data contains one integer number t (1≤t≤1000) — the number of test cases.
The single line of each test case contains two integers n and m (4≤n,m≤200) — the size of matrix B.
It is guaranteed that the sum of n⋅m does not exceed 2⋅105.
输入数据的第一行包含一个整数 t(1≤t≤1000)—— 表示测试用例的数量。
每个测试用例的单独一行包含两个整数 n 和 m(4≤n,m≤200)—— 表示矩阵 B 的尺寸。
保证所有测试用例中 n⋅m 的总和不超过 2⋅105。
输出格式
For each test case, in first line output one integer cnt (1≤cnt≤n⋅m) — the maximum number of different numbers in the matrix.
Then output the matrix B (0≤Bij<263) of size n×m. If there are several correct matrices, it is allowed to output any one.
It can be shown that if there exists a matrix with an optimal number of distinct numbers, then there exists among suitable matrices such a B that (0≤Bij<263).
对于每个测试用例,首先在第一行输出一个整数 cnt (1≤cnt≤n⋅m) —— 矩阵中不同数字的最大个数。
然后输出一个大小为 n×m 的矩阵 B (0≤Bij<263)。若存在多个正确的矩阵,则输出任意一个均可。
可以证明:若存在一个具有最优不同数字个数的矩阵,则在所有满足条件的矩阵中,必存在某个矩阵 B 满足 (0≤Bij<263)。
输入输出样例
输入#1
4 5 5 4 4 4 6 6 6
输出#1
25 9740 1549 9744 1553 9748 1550 1551 1554 1555 1558 10252 2061 10256 2065 10260 2062 2063 2066 2067 2070 10764 2573 10768 2577 10772 16 3108 3109 3112 3113 3110 3111 3114 3115 3620 3621 3624 3625 3622 3623 3626 3627 24 548 549 552 553 556 557 550 551 554 555 558 559 1060 1061 1064 1065 1068 1069 1062 1063 1066 1067 1070 1071 36 25800 25801 25804 25805 25808 25809 25802 4294993099 25806 4294993103 25810 4294993107 26312 26313 26316 26317 26320 26321 26314 4294993611 26318 4294993615 26322 4294993619 26824 26825 26828 26829 26832 26833 26826 4294994123 26830 4294994127 26834 4294994131
说明/提示
In the first test case, there is only 4 submatrix of size 4×4. Consider a submatrix whose upper-left corner coincides with the upper-left corner of the matrix B:
$ \left[ {\begin{array}{cccc} 9740 & 1549 & 9744 & 1553 \ 1550 & 1551 & 1554 & 1555 \ 10252 & 2061 & 10256 & 2065 \ 2062 & 2063 & 2066 & 2067 \ \end{array} } \right] $
9740⊕1549⊕1550⊕1551 = 10256⊕2065⊕2066⊕2067 = 8192;
10252⊕2061⊕2062⊕2063 = 9744⊕1553⊕1554⊕1555 = 8192.
So, chosen submatrix fits the condition. Similarly, you can make sure that the other three submatrices also fit the condition.
在第一个测试用例中,仅有 4 个大小为 4×4 的子矩阵。考虑一个其左上角与矩阵 B 的左上角重合的子矩阵:
$ \left[ {\begin{array}{cccc} 9740 & 1549 & 9744 & 1553 \ 1550 & 1551 & 1554 & 1555 \ 10252 & 2061 & 10256 & 2065 \ 2062 & 2063 & 2066 & 2067 \ \end{array} } \right] $
9740⊕1549⊕1550⊕1551 = 10256⊕2065⊕2066⊕2067 = 8192;
10252⊕2061⊕2062⊕2063 = 9744⊕1553⊕1554⊕1555 = 8192。
因此,所选子矩阵满足条件。类似地,你可以验证其余三个子矩阵也均满足该条件。
输入解题思路,AI测评打分。不知道怎么写?