CF1392E.Omkar and Duck

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

This is an interactive problem.

Omkar has just come across a duck! The duck is walking on a grid with nn rows and nn columns ( 2n252 \leq n \leq 25 ) so that the grid contains a total of n2n^2 cells. Let's denote by (x,y)(x, y) the cell in the xx -th row from the top and the yy -th column from the left. Right now, the duck is at the cell (1,1)(1, 1) (the cell in the top left corner) and would like to reach the cell (n,n)(n, n) (the cell in the bottom right corner) by moving either down 11 cell or to the right 11 cell each second.

Since Omkar thinks ducks are fun, he wants to play a game with you based on the movement of the duck. First, for each cell (x,y)(x, y) in the grid, you will tell Omkar a nonnegative integer ax,ya_{x,y} not exceeding 101610^{16} , and Omkar will then put ax,ya_{x,y} uninteresting problems in the cell (x,y)(x, y) . After that, the duck will start their journey from (1,1)(1, 1) to (n,n)(n, n) . For each cell (x,y)(x, y) that the duck crosses during their journey (including the cells (1,1)(1, 1) and (n,n)(n, n) ), the duck will eat the ax,ya_{x,y} uninteresting problems in that cell. Once the duck has completed their journey, Omkar will measure their mass to determine the total number kk of uninteresting problems that the duck ate on their journey, and then tell you kk .

Your challenge, given kk , is to exactly reproduce the duck's path, i. e. to tell Omkar precisely which cells the duck crossed on their journey. To be sure of your mastery of this game, Omkar will have the duck complete qq different journeys ( 1q1031 \leq q \leq 10^3 ). Note that all journeys are independent: at the beginning of each journey, the cell (x,y)(x, y) will still contain ax,ya_{x,y} uninteresting tasks.

输入格式

输出格式

The interaction will begin with a line containing a single integer nn ( 2n252 \leq n \leq 25 ), the amount of rows and columns in the grid. Read it.

Your program should then print nn lines. The xx -th line should contain nn integers ax,1,ax,2,,ax,na_{x,1}, a_{x,2}, \dotsc, a_{x,n} satisfying 0ax,y10160 \leq a_{x,y} \leq 10^{16} , where ax,ya_{x,y} is the amount of uninteresting problems Omkar should place in the cell (x,y)(x, y) .

After that, you will first receive a single integer qq , the amount of journeys that the duck will take. qq queries will follow; each query will consist of a single line containing an integer kk , the amount of uninteresting problems that the duck ate on that journey. After each query, given that you have determined that the duck visited the cells (x1,y1),(x2,y2),,(x2n1,y2n1)(x_1, y_1), (x_2, y_2), \dotsc, (x_{2n - 1}, y_{2n - 1}) in that order (it should always be true that (x1,y1)=(1,1)(x_1, y_1) = (1, 1) and (x2n1,y2n1)=(n,n)(x_{2n - 1}, y_{2n - 1}) = (n, n) ), you should output 2n12n - 1 lines so that the jj -th line contains the two integers xj,yjx_j, y_j .

Bear in mind that if the sum on your path is kk , but your path is different from the actual hidden path, then your solution is still wrong!

After printing each line do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

  • fflush(stdout) or cout.flush() in C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
  • see documentation for other languages.

Hack Format

To hack, first output a line containing nn and another line containing qq . It must be true that 2n252 \leq n \leq 25 and 1q10001 \leq q \leq 1000 . Then, output the qq journeys taken by the duck in the same format as described above: for each journey, given that the duck visited the cells (x1,y1),(x2,y2),,(x2n1,y2n1)(x_1, y_1), (x_2, y_2), \dotsc, (x_{2n - 1}, y_{2n - 1}) in that order, you should output 2n12n - 1 lines so that the jj -th line contains the two integers xj,yjx_j, y_j . It must be true that (x1,y1)=(1,1)(x_1, y_1) = (1, 1) and (x2n1,y2n1)=(n,n)(x_{2n - 1}, y_{2n - 1}) = (n, n) . Additionally, for each jj such that 2j2n12 \leq j \leq 2n - 1 , it must be true that 1xj,yjn1 \leq x_j, y_j \leq n and either (xj,yj)=(xj1+1,yj1)(x_j, y_j) = (x_{j - 1} + 1, y_{j - 1}) or (xj,yj)=(xj1,yj1+1)(x_j, y_j) = (x_{j - 1}, y_{j - 1} + 1) .

输入输出样例

  • 输入#1

    4
    
    
    
    
    3
    23
    
    
    
    
    
    
    
    26
    
    
    
    
    
    
    
    27

    输出#1

    1 2 3 6
    4 6 2 10
    9 0 7 3
    2 8 8 2
    
    
    1 1
    1 2
    1 3
    2 3
    2 4
    3 4
    4 4
    
    1 1
    2 1
    3 1
    3 2
    3 3
    3 4
    4 4
    
    1 1
    1 2
    1 3
    1 4
    2 4
    3 4
    4 4

说明/提示

The duck's three journeys are illustrated below.

1+2+3+2+10+3+2=231 + 2 + 3 + 2 + 10 + 3 + 2 = 23

1+4+9+0+7+3+2=261 + 4 + 9 + 0 + 7 + 3 + 2 = 26

1+2+3+6+10+3+2=271 + 2 + 3 + 6 + 10 + 3 + 2 = 27

首页