CF1392E.Omkar and Duck

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

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 (2≤n≤252 \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 (1≤q≤1031 \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.

Interaction

The interaction will begin with a line containing a single integer nn (2≤n≤252 \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 0≤ax,y≤10160 \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),…,(x2n−1,y2n−1)(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 (x2n−1,y2n−1)=(n,n)(x_{2n - 1}, y_{2n - 1}) = (n, n)), you should output 2n−12n - 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 2≤n≤252 \leq n \leq 25 and 1≤q≤10001 \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),…,(x2n−1,y2n−1)(x_1, y_1), (x_2, y_2), \dotsc, (x_{2n - 1}, y_{2n - 1}) in that order, you should output 2n−12n - 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 (x2n−1,y2n−1)=(n,n)(x_{2n - 1}, y_{2n - 1}) = (n, n). Additionally, for each jj such that 2≤j≤2n−12 \leq j \leq 2n - 1, it must be true that 1≤xj,yj≤n1 \leq x_j, y_j \leq n and either (xj,yj)=(xj−1+1,yj−1)(x_j, y_j) = (x_{j - 1} + 1, y_{j - 1}) or (xj,yj)=(xj−1,yj−1+1)(x_j, y_j) = (x_{j - 1}, y_{j - 1} + 1).

这是一个交互式问题。

Omkar 刚刚遇到了一只鸭子!这只鸭子正行走在一张 nn 行 nn 列的网格上(2≤n≤252 \leq n \leq 25),因此该网格共包含 n2n^2 个格子。我们用 (x,y)(x, y) 表示从上往下数第 xx 行、从左往右数第 yy 列的格子。此时,鸭子位于格子 (1,1)(1, 1)(即左上角格子),并希望每次向下移动一格或向右移动一格(每秒移动一次),最终到达格子 (n,n)(n, n)(即右下角格子)。

由于 Omkar 认为鸭子很有趣,他想和你玩一个基于鸭子移动的游戏。首先,对于网格中每个格子 (x,y)(x, y),你需要告诉 Omkar 一个非负整数 ax,ya_{x,y}(满足 0≤ax,y≤10160 \leq a_{x,y} \leq 10^{16}),Omkar 将在格子 (x,y)(x, y) 中放置 ax,ya_{x,y} 道无趣的题目。之后,鸭子将从 (1,1)(1, 1) 出发,前往 (n,n)(n, n)。在鸭子整个旅程中所经过的每一个格子 (x,y)(x, y)(包括起点 (1,1)(1, 1) 和终点 (n,n)(n, n)),鸭子都会吃掉该格子中的全部 ax,ya_{x,y} 道无趣题目。当鸭子完成旅程后,Omkar 将称量其体重,从而确定鸭子在本次旅程中总共吃掉的无趣题目数量 kk,并把该值 kk 告诉你。

你的任务是:在已知 kk 的前提下,精确还原鸭子的路径,即准确告诉 Omkar 鸭子在旅程中依次经过了哪些格子。为了验证你对这个游戏的完全掌握,Omkar 将让鸭子完成 qq 次不同的旅程(1≤q≤1031 \leq q \leq 10^3)。注意:所有旅程相互独立——每次旅程开始时,格子 (x,y)(x, y) 中仍含有 ax,ya_{x,y} 道无趣题目。

交互流程

交互开始时,第一行将输入一个整数 nn(2≤n≤252 \leq n \leq 25),表示网格的行数与列数。请读入该值。

随后,你的程序应输出 nn 行。其中第 xx 行应包含 nn 个整数 ax,1,ax,2,…,ax,na_{x,1}, a_{x,2}, \dotsc, a_{x,n},满足 0≤ax,y≤10160 \leq a_{x,y} \leq 10^{16},其中 ax,ya_{x,y} 表示 Omkar 应在格子 (x,y)(x, y) 中放置的无趣题目数量。

接着,你将首先收到一个整数 qq,表示鸭子将进行的旅程次数。随后将有 qq 个查询;每个查询由一行组成,包含一个整数 kk,即鸭子在该次旅程中吃掉的无趣题目总数。对每个查询,在你确定鸭子按顺序经过了格子 (x1,y1),(x2,y2),…,(x2n−1,y2n−1)(x_1, y_1), (x_2, y_2), \dotsc, (x_{2n - 1}, y_{2n - 1}) 后(必须始终满足 (x1,y1)=(1,1)(x_1, y_1) = (1, 1) 且 (x2n−1,y2n−1)=(n,n)(x_{2n - 1}, y_{2n - 1}) = (n, n)),你需要输出 2n−12n - 1 行,其中第 jj 行包含两个整数 xj,yjx_j, y_j。

请注意:若你所构造路径上的数值之和恰好为 kk,但该路径与实际隐藏路径不同,则你的解答仍是错误的!

每次输出一行后,请务必输出换行符并刷新输出缓冲区。否则,你将收到“Idleness limit exceeded”(空闲超时)错误。为此,请使用以下方式:

  • C++ 中使用 fflush(stdout) 或 cout.flush();
  • Java 中使用 System.out.flush();
  • Pascal 中使用 flush(output);
  • Python 中使用 stdout.flush();
  • 其他语言请查阅相应文档。

Hack 格式

用于 hack 时,首先输出一行包含 nn,再输出一行包含 qq。需满足 2≤n≤252 \leq n \leq 25 且 1≤q≤10001 \leq q \leq 1000。然后,以与上述描述相同的格式输出鸭子所走的 qq 条路径:对每条路径,若鸭子按顺序经过格子 (x1,y1),(x2,y2),…,(x2n−1,y2n−1)(x_1, y_1), (x_2, y_2), \dotsc, (x_{2n - 1}, y_{2n - 1}),则需输出 2n−12n - 1 行,其中第 jj 行包含两个整数 xj,yjx_j, y_j。必须满足 (x1,y1)=(1,1)(x_1, y_1) = (1, 1) 且 (x2n−1,y2n−1)=(n,n)(x_{2n - 1}, y_{2n - 1}) = (n, n)。此外,对每个满足 2≤j≤2n−12 \leq j \leq 2n - 1 的 jj,必须满足 1≤xj,yj≤n1 \leq x_j, y_j \leq n,且 (xj,yj)=(xj−1+1,yj−1)(x_j, y_j) = (x_{j - 1} + 1, y_{j - 1}) 或 (xj,yj)=(xj−1,yj−1+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

鸭子的三次旅程如下图所示。

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

输入解题思路,AI测评打分。不知道怎么写?

首页