CF1673F.Anti-Theft Road Planning

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

This is an interactive problem.

A city has n2n^2 buildings divided into a grid of nn rows and nn columns. You need to build a road of some length D(A,B)D(A,B) of your choice between each pair of adjacent by side buildings AA and BB . Due to budget limitations and legal restrictions, the length of each road must be a positive integer and the total length of all roads should not exceed 4800048\,000 .

There is a thief in the city who will start from the topmost, leftmost building (in the first row and the first column) and roam around the city, occasionally stealing artifacts from some of the buildings. He can move from one building to another adjacent building by travelling through the road which connects them.

You are unable to track down what buildings he visits and what path he follows to reach them. But there is one tracking mechanism in the city. The tracker is capable of storing a single integer xx which is initially 00 . Each time the thief travels from a building AA to another adjacent building BB through a road of length D(A,B)D(A,B) , the tracker changes xx to xD(A,B)x\oplus D(A,B) . Each time the thief steals from a building, the tracker reports the value xx stored in it and resets it back to 00 .

It is known beforehand that the thief will steal in exactly kk buildings but you will know the values returned by the tracker only after the thefts actually happen. Your task is to choose the lengths of roads in such a way that no matter what strategy or routes the thief follows, you will be able to exactly tell the location of all the buildings where the thefts occurred from the values returned by the tracker.

输入格式

输出格式

First read a single line containing two integers nn (2n32)(2\leq n\leq 32) and kk (1k1024)(1\leq k\leq 1024) denoting the number of rows and number of thefts respectively.

Let's denote the jj -th building in the ii -th row by Bi,jB_{i,j} .

Then print nn lines each containing n1n-1 integers. The jj -th integer of the ii -th line must be the value of D(Bi,j,Bi,j+1)D(B_{i,j},B_{i,j+1}) .

Then print n1n-1 lines each containing nn integers. The jj -th integer of the ii -th line must be the value of D(Bi,j,Bi+1,j)D(B_{i,j},B_{i+1,j}) .

Remember that the total length of the roads must not exceed 4800048\,000 .

Then answer kk queries. First read the value xx returned by the tracker. Then print two integers denoting the row number and column number of the building where the theft occurred. After that you will be able to answer the next query (if such exists).

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

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

Hacks

You cannot make hacks in this problem.

输入输出样例

  • 输入#1

    2 4
    
    
    
    14
    
    1
    
    14
    
    3

    输出#1

    1
    8
    2 4
    
    1 2
    
    1 1
    
    1 2
    
    2 1

说明/提示

For the sample test, n=2n=2 and k=4k=4 .

You choose to build the roads of the following lengths:

The thief follows the following strategy:

  1. Start at B1,1B_{1,1} .
  2. Move Right to B1,2B_{1,2} .
  3. Move Down to B2,2B_{2,2} .
  4. Move Left to B2,1B_{2,1} .
  5. Move Up to B1,1B_{1,1} .
  6. Move Right to B1,2B_{1,2} .
  7. Steal from B1,2B_{1,2} .
  8. Move Left to B1,1B_{1,1} .
  9. Steal from B1,1B_{1,1} .
  10. Move Down to B2,1B_{2,1} .
  11. Move Right to B2,2B_{2,2} .
  12. Move Up to B1,2B_{1,2} .
  13. Steal from B1,2B_{1,2} .
  14. Move Left to B1,1B_{1,1} .
  15. Move Down to B2,1B_{2,1} .
  16. Steal from B2,1B_{2,1} .

The tracker responds in the following way:

  1. Initialize x=0x=0 .
  2. Change xx to x1=01=1x\oplus 1=0\oplus1=1 .
  3. Change xx to x4=14=5x\oplus 4=1\oplus4=5 .
  4. Change xx to x8=58=13x\oplus 8=5\oplus8=13 .
  5. Change xx to x2=132=15x\oplus 2=13\oplus2=15 .
  6. Change xx to x1=151=14x\oplus 1=15\oplus1=14 .
  7. Return x=14x=14 and re-initialize x=0x=0 .
  8. Change xx to x1=01=1x\oplus 1=0\oplus1=1 .
  9. Return x=1x=1 and re-initialize x=0x=0 .
  10. Change xx to x2=02=2x\oplus 2=0\oplus2=2 .
  11. Change xx to x8=28=10x\oplus 8=2\oplus8=10 .
  12. Change xx to x4=104=14x\oplus 4=10\oplus4=14 .
  13. Return x=14x=14 and re-initialize x=0x=0 .
  14. Change xx to x1=01=1x\oplus 1=0\oplus1=1 .
  15. Change xx to x2=12=3x\oplus 2=1\oplus2=3 .
  16. Return x=3x=3 and re-initialize x=0x=0 .
首页