欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2070B.Robot Program
Robot Program
There is a robot on the coordinate line. Initially, the robot is located at the point (). The robot has a sequence of commands of length consisting of characters, where L represents a move to the left by one unit (from point to point ) and R represents a move to the right by one unit (from point to point ).
The robot starts executing this sequence of commands (one command per second, in the order they are presented). However, whenever the robot reaches the point , the counter of executed commands is reset (i. e. it starts executing the entire sequence of commands from the very beginning). If the robot has completed all commands and is not at , it stops.
Your task is to calculate how many times the robot will enter the point during the next seconds.
Input
The first line contains a single integer () — the number of test cases.
The first line of a test case contains three integers , and (; ; ).
The second line of a test case contains a string consisting of characters L and/or R.
Additional constraint on the input: the sum of over all test cases doesn't exceed .
Output
For each test case, print a single integer — the number of times the robot will enter the point during the next seconds.
Note
In the first example, the robot moves as follows: $2 \rightarrow 1 \rightarrow \underline{0} \rightarrow -1 \rightarrow -2 \rightarrow -1$. The robot has completed all instructions from the sequence and is not at . So it stops after seconds and the point is entered once.
In the second example, the robot moves as follows: $-1 \rightarrow \underline{0} \rightarrow 1 \rightarrow \underline{0} \rightarrow 1 \rightarrow \underline{0} \rightarrow 1 \rightarrow \underline{0} \rightarrow 1$. The robot worked seconds and the point is entered times.
In the third example, the robot moves as follows: $-2 \rightarrow -3 \rightarrow -2 \rightarrow -1 \rightarrow \underline{0} \rightarrow -1$. The robot worked seconds and the point is entered once.
In the fourth example, the robot moves as follows: $3 \rightarrow 2 \rightarrow 3 \rightarrow 4 \rightarrow 3 \rightarrow 2$. The robot has completed all instructions from the sequence and is not at . So it stops after seconds, without reaching the point .
Samples
6
3 2 6
LLR
2 -1 8
RL
4 -2 5
LRRR
5 3 7
LRRLL
1 1 1
L
3 -1 4846549234412827
RLR
1
4
1
0
1
2423274617206414
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |