CF1775F.Laboratory on Pluto

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

As you know, Martian scientists are actively engaged in space research. One of the highest priorities is Pluto. In order to study this planet in more detail, it was decided to build a laboratory on Pluto.

It is known that the lab will be built of nn square blocks of equal size. For convenience, we will assume that Pluto's surface is a plane divided by vertical and horizontal lines into unit squares. Each square is either occupied by a lab block or not, and only nn squares are occupied.

Since each block is square, it has four walls. If a wall is adjacent to another block, it is considered inside, otherwise — outside.

Pluto is famous for its extremely cold temperatures, so the outside walls of the lab must be insulated. One unit of insulation per exterior wall would be required. Thus, the greater the total length of the outside walls of the lab (i. e., its perimeter), the more insulation will be needed.

Consider the lab layout in the figure below. It shows that the lab consists of n=33n = 33 blocks, and all the blocks have a total of 2424 outside walls, i. e. 2424 units of insulation will be needed.

You should build the lab optimally, i. e., minimize the amount of insulation. On the other hand, there may be many optimal options, so scientists may be interested in the number of ways to build the lab using the minimum amount of insulation, modulo a prime number mm .

Two ways are considered the same if they are the same when overlapping without turning. Thus, if a lab plan is rotated by 9090^{\circ} , such a new plan can be considered a separate way.

To help scientists explore Pluto, you need to write a program that solves these difficult problems.

输入格式

The first line contains two integers tt and uu ( 1t21051 \le t \le 2\cdot 10^5 , 1u21 \le u \le 2 ) — the number of test cases and the test type. If u=1u=1 , you need to find any way to build the lab in an optimal way, and if u=2u=2 , you need to calculate the number of ways to do it.

If u=2u=2 , then in the following line of input there is a prime integer mm ( 108m109+910^8 \le m \le 10^9 + 9 ), modulo which you need to calculate the number of ways.

Each of the following tt lines of input contains a description of a test case consisting of one integer nn ( 1n41051 \le n \le 4\cdot 10^5 ) — the number of blocks the lab should consist of.

It is guaranteed that if u=1u=1 , then the sum of nn on all test cases does not exceed 81058\cdot10^5 .

输出格式

For each test case, output the answers in the format below, separating them with a newline. The output format depends on uu in the input data.

If u=1u=1 , in the first line you need to print two integers hh and ww —the height and width of the area in which the lab should be built. Then, in each of the following hh lines, you must output a line sis_i consisting of ww characters "#" and ".". If the jj -th character of the row sis_i is "#", then the corresponding square must contain a block of laboratory, otherwise, it is considered empty. Thus, we get a matrix of symbols. The condition must also be met that the first and last rows of the matrix, as well as the first and last columns, must have at least one character "#", otherwise we could output the same lab layout, but with smaller hh and ww . If there are many options to build an optimal lab, you can print any of them.

If u=2u=2 , you need to print two integers pp and cc — the number of outside walls in an optimal lab, and the remainder of the number of ways by prime modulo mm .

输入输出样例

  • 输入#1

    3 1
    1
    2
    7

    输出#1

    1 1
    #
    1 2
    ##
    2 4
    .###
    ####
  • 输入#2

    3 2
    1000000007
    1
    2
    7

    输出#2

    4 1
    6 2
    12 22

说明/提示

Consider the second example.

If n=1n=1 , the only way to build a lab is to place a single block. In this case, the perimeter will be equal to four.

When n=2n=2 , you must place two blocks side by side. This can be done either vertically or horizontally, so there are two ways. It is easy to see that the lab has six outside walls in this case.

For n=7n=7 , all the 2222 optimal plans are shown in the picture below.

首页