CF1801A.The Very Beautiful Blanket

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Kirill wants to weave the very beautiful blanket consisting of n×mn \times 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 BB matrix of size n×mn \times m consisting of non-negative integers.

Kirill considers that the blanket is very beautiful, if for each submatrix AA of size 4×44 \times 4 of the matrix BB is true:

  • A11A12A21A22=A33A34A43A44,A_{11} \oplus A_{12} \oplus A_{21} \oplus A_{22} = A_{33} \oplus A_{34} \oplus A_{43} \oplus A_{44},
  • A13A14A23A24=A31A32A41A42,A_{13} \oplus A_{14} \oplus A_{23} \oplus A_{24} = A_{31} \oplus A_{32} \oplus A_{41} \oplus A_{42},

where \oplus 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 nn and mm .

Your task is to generate a matrix BB of size n×mn \times m , which corresponds to a very beautiful blanket and in which the number of different numbers maximized.

输入格式

The first line of input data contains one integer number tt ( 1t10001 \le t \le 1000 ) — the number of test cases.

The single line of each test case contains two integers nn and mm (4n,m200)(4 \le n, \, m \le 200) — the size of matrix BB .

It is guaranteed that the sum of nmn \cdot m does not exceed 21052 \cdot 10^5 .

输出格式

For each test case, in first line output one integer cntcnt (1cntnm)(1 \le cnt \le n \cdot m) — the maximum number of different numbers in the matrix.

Then output the matrix BB (0Bij<263)(0 \le B_{ij} < 2^{63}) of size n×mn \times 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 BB that (0Bij<263)(0 \le B_{ij} < 2^{63}) .

输入输出样例

  • 输入#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×44 \times 4 . Consider a submatrix whose upper-left corner coincides with the upper-left corner of the matrix BB :

$ \left[ {\begin{array}{cccc} 9740 & 1549 & 9744 & 1553 \ 1550 & 1551 & 1554 & 1555 \ 10252 & 2061 & 10256 & 2065 \ 2062 & 2063 & 2066 & 2067 \ \end{array} } \right] $

97401549155015519740 \oplus 1549 \oplus 1550 \oplus 1551 == 1025620652066206710256 \oplus 2065 \oplus 2066 \oplus 2067 == 81928192 ;

1025220612062206310252 \oplus 2061 \oplus 2062 \oplus 2063 == 97441553155415559744 \oplus 1553 \oplus 1554 \oplus 1555 == 81928192 .

So, chosen submatrix fits the condition. Similarly, you can make sure that the other three submatrices also fit the condition.

首页