#P12822. [NERC 2021] Interactive Treasure Hunt

    ID: 12602 Type: RemoteJudge 3000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 4 Uploaded By: Tags>2021交互题Special Judge构造ICPCAd-hocNERC/NEERC

[NERC 2021] Interactive Treasure Hunt

题目描述

This is an interactive problem.\textit{This is an interactive problem.}

There is a grid of n×mn\times m cells. Two treasure chests are buried in two different cells of the grid. Your task is to find both of them. You can make two types of operations:

  • DIG\tt{DIG} rr cc: try to find the treasure in the cell (r,c)(r, c). The interactor will tell you if you found the treasure or not.
  • SCAN\tt{SCAN} rr cc: scan from the cell (r,c)(r, c). The result of this operation is the sum of Manhattan distances from the cell (r,c)(r, c) to the cells where the treasures are hidden. Manhattan distance from a cell (r1,c1)(r_1, c_1) to a cell (r2,c2)(r_2, c_2) is calculated as r1r2+c1c2|r_1 - r_2| + |c_1 - c_2|. You need to find the treasures in at most 7 operations. This includes both DIG\tt{DIG} and SCAN\tt{SCAN} operations in total. To solve the test you need to call DIG\tt{DIG} operation at least once in both of the cells where the treasures are hidden.

Interactive Protocol

Your program has to process multiple test cases in a single run. First, the testing system writes tt --- the number of test cases (1t1001\le t \le 100). Then, tt test cases should be processed one by one.

In each test case, your program should start by reading the integers nn and mm (2n,m162 \le n, m \le 16).

Then, your program can make queries of two types:

  • DIG\tt{DIG} rr cc (1rn1\le r\le n; 1cm1\le c\le m). The interactor responds with integer 11, if you found the treasure, and 00 if not. If you try to find the treasure in the same cell multiple times, the result will be 00 since the treasure is already found.

  • SCAN\tt{SCAN} rr cc (1rn1\le r\le n; 1cm1\le c\le m). The interactor responds with an integer that is the sum of Manhattan distances from the cell (r,c)(r, c) to the cells where the treasures were hidden. The sum is calculated for both cells with treasures, even if you already found one of them.

After you found both treasures, i.e. you received 11 for two DIG\tt{DIG} operations, your program should continue to the next test case or exit if that test case was the last one.

输入格式

See Interactive Protocol.

输出格式

See Interactive Protocol.

1
2 3

1

1

3

0

1


SCAN 1 2

DIG 1 2

SCAN 2 2

DIG 1 1

DIG 1 3