시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 1024 MB65583.333%

문제

You are MALL-E, the mall scooter scooper robot. Your job is to fetch all the misplaced mall scooters at the end of the day and return them to the scooter depot. The mall is an infinite grid, containing $n$ scooters that need to be returned. You can move in one of four directions: up, down, left, or right, and each move takes one second. If you move to a location that contains a scooter, that scooter moves to the next location in the same direction you were moving. If a scooter moves into a location that contains another scooter, the same thing happens, so there is never more than one scooter at each location and you never occupy the same location as a scooter. If a scooter moves to the scooter depot, it disappears. However, the robot can freely move over the scooter depot.

The mall will soon open. You need to find a way to get all the scooters to the depot in at most $10^5$ seconds.

A picture of Sample Input 2. The two leftmost scooters can be pushed in the depot by moving up three times and moving right twice.

입력

The first line of the input contains a single integer $n$ ($1 \leq n \leq 50$). The next line contains four integers $x_0$, $y_0$, $x_t$, and $y_t$ ($0 \leq x_0, y_0, x_t, y_t \leq 30$). This indicates that you start at $(x_0, y_0)$ and the depot is located at $(x_t, y_t)$. Then follow $n$ lines, each containing two integers $x$ and $y$ ($0 \leq x, y \leq 30$). This indicates that there is a scooter located at $(x, y)$. You, the depot, and all the scooters will all have distinct locations.

출력

The output should contain a sequence of instructions, each on its own line. An instruction is one of the following strings: "up". "down", "left", or "right".

예제 입력 1

1
0 0 2 0
1 0

예제 출력 1

right

예제 입력 2

8
1 1 4 4
5 4
6 4
3 4
2 4
4 5
4 6
4 3
4 2

예제 출력 2

up
up
up
right
right
down
down
down
right
up
up
right
right
right
up
left
left
up
up
up
left
down
down

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Nordic Collegiate Programming Contest > NCPC 2022 J번

  • 문제를 만든 사람: Nils Gustafsson