Nộp bài | Các bài nộp | Làm tốt nhất | Về danh sách bài |
HNROBOT - Điều khiển robot |
Problem: Andrysha is fond of computer games. He recently found another exciting game:
The game world is an infinite plane, divided into cells. Each cell has its own coordinates. The player controls a robot, initially located at the cell with coordinates (0, 0). The player can move the robot left, up, right, and down by pressing specific keyboard buttons. Specifically:
- Every time the button 'L' is pressed, the first coordinate of the robot decreases by 1.
- Every time the button 'U' is pressed, the second coordinate of the robot increases by 1.
- Every time the button 'R' is pressed, the first coordinate of the robot increases by 1.
- Every time the button 'D' is pressed, the second coordinate of the robot decreases by 1.
The goal is to move the robot to a given cell (x, y). However, the game sounds easy, and Andrysha was unable to finish it, so he asked his friend Zhenya for help. Zhenya told him the sequence of button presses he used, but this hint didn't help (maybe Zhenya had a different target cell)! Andrysha went mad and slammed the keyboard so hard that some buttons broke. Broken buttons no longer respond to presses, which might actually help!
Andrysha wants to determine if he can finish the game using Zhenya's instructions, while also breaking some buttons at certain moments. Pressing a broken button has no effect on the robot. Andrysha can break any button before any press or after any press. Moreover, he can break multiple buttons (even all of them) at the same time, and can break them before the very first press. He always breaks the remaining buttons at the end of the game.
Input: The first line of the input contains an integer n (1 ≤ n ≤ 1,000,000) — the length of Zhenya's list of instructions.
The following line contains n characters 'L', 'U', 'R', 'D' — the list of instructions.
The third line of the input contains two integers x and y (-1,000,000 ≤ x, y ≤ 1,000,000), denoting the coordinates of the target cell where the robot should be located after performing all the instructions.
Output: If there is no way for Andrysha to succeed, print -1.
Otherwise, output four integers from 0 to n, representing the moment of time when Andrysha should break buttons "L", "U", "R", "D", respectively. If a button should be broken before any pressings, print 0 for it. Since Andrysha breaks all the remaining buttons at the end of the game, every printed number should be between 0 and n.
If there is more than one solution, print any of them.
Ví dụ:
Input:
4
LRUD
3 2
Output:
-1
Input:
4
DURL
0 0
Output:
0 0 0 0
Input:
8
LLURDRRD
1 -1
Output:
1 7 6 8
In the first sample, the destination cell is too far from the starting cell, so the robot can't reach it in four or less pressings. In the second sample, all buttons can be broken before the beginning of the game, so robot will stay at the starting-destination point. In the third sample, if all buttons are broken according to the answer, the resulting sequence of robot's actions will be the LURDRD and robot will reach the destination.
Được gửi lên bởi: | noname00.pas |
Ngày: | 2017-11-28 |
Thời gian chạy: | 0.100s |
Giới hạn mã nguồn: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Ngôn ngữ cho phép: | C-CLANG C CSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG C99 JAVA PAS-FPC PYTHON PYTHON3 |
Nguồn bài: | Bài tập Ôn HN 01/2017 (Thầy Nguyễn Đức Nghĩa) |