CF637D.Running with Obstacles
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A sportsman starts from point x__start = 0 and runs to point with coordinate x__finish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates _x_1, _x_2, ..., x__n. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
一名运动员从起点 xstart=0 出发,沿一条直线跑向终点 xfinish=m。此外,该运动员可以跳跃:跳跃前必须先助跑至少 s 米(即这 s 米的路径上不能有任何障碍物),之后可跳跃跨越至多 d 米的距离。跑步与跳跃均只允许从左向右进行。他只能在整数坐标点起跳或落地,且这些点上不能有障碍物。为越过某个障碍物,他必须落在严格位于该障碍物右侧的点上。
运动员前进路径上有 n 个障碍物,其坐标分别为 x1,x2,…,xn。他无法穿过障碍物,只能通过跳跃越过它们。你的任务是判断该运动员是否能够到达终点。
输入格式
The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a sequence of n integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
输入的第一行包含四个整数 n、m、s 和 d(1 ≤ n ≤ 200000,2 ≤ m ≤ 109,1 ≤ s,d ≤ 109),分别表示跑步者路径上的障碍物数量、终点坐标、起跳前的奔跑距离以及最大跳跃长度。
第二行包含一个由 n 个整数 a1,a2,...,an(1 ≤ ai ≤ m − 1)组成的序列,表示各障碍物的坐标。保证起点和终点处均无障碍物,且任意位置至多存在一个障碍物;障碍物坐标以任意顺序给出。
输出格式
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
- print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters;
- print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
如果运动员无法到达终点,则在输出的第一行打印 “IMPOSSIBLE”(不带引号)。
如果运动员能够从起点到达终点,则按如下格式输出任意一种可行方案:
- 若运动员应再奔跑 X 米,则输出一行形如 “RUN X>” 的内容(其中 X 应为正整数);
- 若运动员开始起跳,且应在空中继续飞行 Y 米,则输出一行形如 “JUMP Y” 的内容(其中 Y 应为正整数)。
所有 “RUN” 和 “JUMP” 指令必须严格交替出现,且以 “RUN” 开始;此外,指令须按时间顺序输出。不允许在跳跃过程中越过终点,但允许在跳跃结束后恰好落在终点处。运动员一旦到达终点,即应立即停止。
输入输出样例
输入#1
3 10 1 3 3 4 7
输出#1
RUN 2 JUMP 3 RUN 1 JUMP 2 RUN 2
输入#2
2 9 2 3 6 4
输出#2
IMPOSSIBLE
输入解题思路,AI测评打分。不知道怎么写?