luogu#P9353. [JOI 2023 Final] Modern Machine
[JOI 2023 Final] Modern Machine
题目描述
Bitaro is given JOI machine as a birthday present. JOI machine consists of one ball, light tiles, and buttons. The light tiles are numbered from to . When Bitaro turns the power on, Light tile () emit light of color (blue () or red ()). The buttons are numbered from to . If Bitaro pushes Button (), the following happen.
- The ball is placed on Light tile .
- Light tile becomes red (regardless of its original color).
- The following operations are performed until the ball is removed.
Let be the index of the light tile where the ball is currently placed.- If Light tile is blue,
Light tile becomes red. After that, if , the ball is removed. Otherwise, the ball moves to Light tile . - If Light tile is red,
Light tile becomes blue. After that, if , the ball is removed. Otherwise, the ball moves to Light tile .
- If Light tile is blue,
Bitaro is interested in JOI machine. He plans to perform experiments. In the -th experiment (), after Bitaro turns the power on, Bitaro pushes Buttons in this order. After Bitaro pushes a button, he will not push the next button and wait until the ball is removed.
Given information of JOI machine and the experiments, write a program which calculates, for each experi- ment, the number of light tiles whose colors are red when the experiment finishes.
输入格式
Read the following data from the standard input.
输出格式
Write lines to the standard output. In the -th line (), the output should contain the number of light tiles whose colors are red when the -th experiment finishes.
5 1
RBRRB
4
1
1 1
1
5 3
RBRBR
1 3 4
2
2 3
1 3
5
0
10 3
BBRRBRBRRB
2 10 5
1
1 3
2
10 10
RRRRRRRRRR
3 1 4 1 5 9 2 6 5 3
5
1 7
2 8
3 9
4 10
1 10
4
8
10
0
9
10 10
RRRBBBBBBB
3 1 4 1 5 9 2 6 5 3
5
1 10
2 9
3 8
4 7
5 6
2
6
0
10
7
30 10
RRRBBRBBBRBBBRBRBRRRRRBBBBRBRR
3 28 2 29 1 30 6 14 7 7
10
1 10
2 3
2 5
2 8
3 3
3 6
4 5
4 7
5 9
10 10
21
15
15
4
17
16
14
20
12
23
提示
【样例解释 #1】
The first experiment proceeds as follows.
- Bitaro pushes Button 1, and ball is placed on Light tile 4.
- Light tile 4 becomes red. Since the original color of Light tile 4 is red, the color of Light tile 4 does not change.
- After that, the following operations are performed.
(1)Since the current color of Light tile 4 is red, Light tile 4 becomes blue, and the ball moves to Light tile 5.
(2)Since the current color of Light tile 5 is blue, Light tile 5 becomes red, and the ball moves to Light tile 4.
(3)Since the current color of Light tile 4 is blue, Light tile 4 becomes red, and the ball moves to Light tile 3.
(4)Since the current color of Light tile 3 is red, Light tile 3 becomes blue, and the ball moves to Light tile 4.
(5)Since the current color of Light tile 4 is red, the color of Light tile 4 becomes blue, and the ball moves to Light tile 5.
(6)Since the current color of Light tile 5 is red, the color of Light tile 5 becomes blue, and the ball is removed.
After the experiment, Light tile 1 is the only light tile whose current color is red. Therefore, output 1.
本样例满足子任务 1,2,3,6,7 的限制。
【样例解释 #2】
For the first experiment, Light tiles 1, 2, 3, 4, 5 are the light tiles whose current colors are red after the experiment. Since there are five such light tiles, output 5.
For the second experiment, there is no light tile whose current color is red after the experiment. Therefore, output 0.
本样例满足子任务 3,6,7 的限制。
【样例解释 #3】
本样例满足子任务 1,2,3,6,7 的限制。
【样例解释 #4】
本样例满足子任务 3,4,5,6,7 的限制。
【样例解释 #5】
本样例满足子任务 3,5,6,7 的限制。
【样例解释 #6】
本样例满足子任务 6,7 的限制。
【数据规模】
对全部的测试点,保证:
- ;
- ;
- ;
- ;
- ;
- ;
- 均为整数。
【子任务】
本题采用捆绑测试。
- (3 points) ,。
- (12 points) ,。
- (10 points) 。
- (11 points) ,。
- (26 points) 存在一个整数 ,满足对 ,;且对 ,。
- (17 points) 或 。
- (21 points) 无特殊约定。