PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SRD0000051. Các băng chuyền (Conveyor Belts)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Các băng chuyền (Conveyor Belts)
Conveyor Belts
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
An grid contains one conveyor belt in each cell. A ^ belt moves upward, < moves left, and > moves right. Rows are numbered from top to bottom and columns from left to right, beginning at .
Process:
A x y: launch an object at cell and follow the belts until it exits the grid or loops forever. Output the first outside coordinate (top row , left column , or right column ), or-1 -1for an infinite cycle.C x y c: change cell to belt direction .
Each A event is independent and does not modify the board.
Input
The first line gives , followed by strings of length using ^, <, >. Next come events A x y or C x y c. There are at most C events.
Output
For each A event, print two integers: the exit coordinate or -1 -1 if the path loops.
Subtasks
- Subtask 1 (10 points): ; . Grid width and at most changes.
- Subtask 2 (20 points): ; . Grid width and at most changes.
- Subtask 3 (25 points): ; . Grid width and at most changes.
- Subtask 4 (45 points): ; . Grid width and at most changes.
Examples
Input
2 2 3
>>
^^
A 2 1
C 1 2 <
A 2 1
Output
1 3
-1 -1
Explanation
Initially the object travels and exits at 1 3. After changing to <, the two top-row cells form a two-cell cycle, giving -1 -1.