European Girls' Olympiad in Informatics: 2023 Day 1 Problem 3
Maj is a robotics researcher who works at Lund University. She has learned about a valuable treasure in the cellar of the university. The treasure is in a box located in an empty room deep underground. Unfortunately, Maj cannot just go and look for the box. It is very dark in the cellar and going there with a light would raise suspicion. Her only way to find the treasure is to remotely control a robot vacuum cleaner that inhabits the cellar.
The cellar is represented as an grid, where the rows are numbered from to (top to bottom) and the columns are numbered from to (left to right), meaning that the top left cell is and the bottom right cell is . The box with the treasure is in some unknown cell, other than the cell . Every night, the robot vacuum cleaner starts in the top left corner and moves around the cellar.
Each night, Maj can give the robot a sequence of instructions on how it should move in the form of a string consisting of characters <
, >
, ^
, and v
. Formally, if the robot is standing on cell that is unblocked on all sides, <
moves the robot left to cell , >
moves the robot right to cell , ^
moves the robot up to cell , and v
moves the robot down to cell .
The cellar walls are solid, so if the robot attempts to move outside the grid, nothing will happen. The box is also solid, and cannot be pushed. At the end of each night, the robot will report its location and go back to the top left corner.
Time is of the essence, so Maj decides to find the box in as few nights as possible.
Interaction
This is an interactive problem.
- Your program should start by reading a line with two integers and : the height and width of the grid.
- Then, your program should interact with the grader. In each round of interaction, you should print a question mark
?
followed by a non-empty string consisting of characters<
,>
,^
,v
. The length of this string can be at most . Then, your program should read two integers and , the location of the robot after executing the instructions. Note that the robot always goes back to after each query. - When you know the location of the box, print
!
followed by the two integers , the row and column of the box . After this, your program must exit without making any further queries. This final output does not count as a query when determining your score.
Make sure to flush standard output after issuing a query, or else your program might get judged as Time Limit Exceeded. In Python, print()
flushes automatically.
In C++, cout << endl;
also flushes in addition to printing a newline; if using printf, use fflush(stdout)
.
The grader is non-adaptive, meaning that the position of the box is determined before the interaction begins.
Note that upon receiving invalid input, the interactorr will terminate and stop communicating with your submission.
Constraints and Scoring
- .
- The box will never be located at . This means that .
- Each query can consist of at most instructions.
- You can issue at most queries (printing the final answer does not count as a query).
Your solution will be tested on a number of test cases. If your solution fails on any of these test cases (e.g. by reporting the wrong box position - Wrong Answer, crashing - Runtime Error, exceeding the time limit - Time Limit Exceeded, etc.), you will receive 0 points and the appropriate verdict.
If your program successfully finds the position of the box in all test cases, you will get the verdict Accepted, and a score calculated as follows: where is the maximum number of queries used on any test case. Printing the final answer does not count as a query. The score will be rounded to the nearest integer.
In particular, to receive 100 points, your program must solve every test case using at most queries. The table below shows some values of and the associated score.
2 | 3 | 4 | 5 | 20 | 50 | 2500 | ||||
Score | 100 | 82 | 71 | 63 | 32 | 20 | 3 |
Testing Tool
To facilitate the testing of your solution, we provide a simple tool that you can download (testing_tool.py). The tool is optional to use, and you are allowed to change it. Note that the official grader program is different from the testing tool.
Example usage (with , , and the hidden box at position ):
For Python programs, say solution.py
(normally run as pypy3 solution.py
):
python3 testing_tool.py pypy3 solution.py <<<"4 5 2 3"
For C++ programs, first compile it (e.g., with g++ -g -O2 -std=gnu++17 -static solution.cpp -o solution.out
) and then run:
python3 testing_tool.py ./solution.out <<<"4 5 2 3"
Sample Interaction
>>>
denotes your output. Do not print this out.
4 5
>>> ? vv>>>>>><^^^^^>
0 2
>>> ? >>>>>>>>vvvvvvvvvv
3 4
>>> ! 2 3
Explanation for Sample Interaction
The grid has height and width , and the box is at position .
The figure below shows the robot's path when following the instructions of the first query ? vv>>>>>>^
.
It results in the robot ending up at position .
Before the second query, the robot will go back to the top left corner again.
Then the solution issues another query ? >>>>>>>vvvvvvvvvv
for which the robot ends up in the bottom right corner .
Now the solution decides to guess the answer, by writing ! 2 3
, which is the correct position of the box.
Comments