Honing In


Submit solution

Points: 1
Time limit: 1.5s
Memory limit: 256M

Author:
Problem type
Allowed languages
C, C++, Java, Python

Nice job with your cleaning duties at AUCPL.inc. We've decided to promote you to junior problemsetter, where you can begin contributing to our many high-quality programming contests.

To begin your new job, you need to find your desk. The office at AUCPL.inc is, depressingly, a grid with n rows and m columns of desks. The top-left desk is at (1, 1), and the bottom-right desk is at (n, m). Being surrounded by so many coworkers is already quite overwhelming.

Luckily, your coworkers are (mostly) helpful. If you ask the worker sitting at desk (r,c) where your assigned desk is, they will respond with one of four cardinal directions:

  • U (up)
  • D (down)
  • L (left)
  • R (right)

This direction is guaranteed to point towards your desk (decrease Manhattan distance), though it is not necessarily the shortest or most direct route.

  • For example, if your desk is exactly 1 unit above and 100 units to the right of the coworker, they might say U or R.
  • For example, if your desk is exactly 50 units below the coworker, they will always say D.

There is one exception: the coworker currently sitting at your desk. They've been laid off, and are not feeling very cooperative. Instead of giving useful information, they will always respond with a random direction.

By querying coworkers strategically, can you determine the location of your assigned desk?

Interaction

This is an interactive problem. Your submission will be run against an interactor, which reads from the standard output of your program and writes to its standard input. The interaction must follow the format below.

The interactor first sends two integers n and m (1 \leq n, m \leq 10^{18}), representing the dimensions of your office floor.

Your program may then send at most 150 commands to determine the location of your desk. To query a coworker, print a line in the form r\ c\ \texttt{?}, where (1 \leq r \leq n) and (1 \leq c \leq m), meaning you ask the coworker at desk (r,c) where your desk is.

The interactor will respond with a single character d, where d \in \{U, D, L, R\}, indicating the direction given by that coworker. If the coworker at (r, c) returns a direction d, then moving one step from (r, c) in direction d results in a position that is strictly closer (in Manhattan distance) to your desk.

The only exception is the coworker currently sitting at your desk, who gives a uniformly random direction instead, with each of U, D, L, and R chosen independently with probability \frac{1}{4} for every query.

For any desk other than your own, repeated queries to the same (r,c) will always return the same direction.

Once you know the location of your desk, print a line in the form r\ c\ \texttt{!} where (1 \leq r \leq n) and (1 \leq c \leq m), meaning you attempt to claim the desk at (r,c).

You will receive a Wrong Answer if:

  • You send more than 150 ? commands, or
  • Your ! command is not the true location of your desk.

Example

Interaction 1
> 3 3
< 1 1 ?
> D
< 3 3 ?
> U
< 2 2 ?
> R
< 2 3 ?
> D
< 2 3 ?
> U
< 2 3 !
Explanation 1

Your desk is at (2,3). Here's a breakdown of the interaction:

  • The employee at desk (1,1) says your desk is below them (D). They could have said D or R.
  • The employee at desk (3,3) says your desk is above them (U). They could only have said U, as your desk is in the same column.
  • The employee at desk (2,2) says your desk is to the right of them (R). They could only have said R, as your desk is on the same row.
  • The employee at desk (2,3) says your desk is below them (D). They could have given any direction.
  • The employee at desk (2,3) says your desk is above them (U). They could have given any direction.
  • You guess desk (2,3), which is correct.

The directions the employees would give are visualised below:

Interaction 2
> 6 7
< 2 2 ?
> D
< 5 2 ?
> R
< 4 4 ?
> U
< 3 5 ?
> L
< 3 4 ?
> D
< 4 4 ?
> U
< 3 4 ?
> L
< 3 4 !
Explanation 2

The directions the employees would give are visualised below:


Comments

There are no comments at the moment.