#arc175a. A - Spoon Taking Problem
A - Spoon Taking Problem
Score: points
问题陈述
个人围坐在一张圆桌旁,按逆时针顺序编号为 至 。每个人都有一个主导手:左手或右手。
圆桌上有 把勺子,编号为 至 ,每两个人之间放置一把勺子。对于每个 ,人 的左边和右边分别有勺子 和 。这里,勺子 指的是勺子 。
下面是 时的示意图。
你将得到一个排列 ,它是由 组成的。按照顺序 ,人 将执行以下操作:
- 如果左边或右边还有勺子,他们将拿走其中一把。
- 如果两边都还有勺子,他们将拿走他们主导手那边的勺子。
- 否则,他们将不做任何操作。
你还得到了一个长度为 的字符串 ,由 L
、R
和 ?
组成。在 种可能的主导手组合中,找出满足以下所有条件的数量,对 取模:
- 如果 中的第 个字符是
L
,则人 是左撇子。 - 如果 中的第 个字符是
R
,则人 是右撇子。 - 当每个人都完成操作后,每个人都拿到了一把勺子。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
people are sitting around a round table, and numbered to in a counterclockwise order. Each person has a dominant hand: left or right.
There are spoons numbered to on the round table, with one spoon placed between each pair of adjacent people. For each , to the left and right of person , there are spoons and , respectively. Here, spoon refers to spoon .
Below is a diagram for .
You are given a permutation of . In the order , person will act as follows:
- If there is a spoon remaining on left or right side, they will take one of them.
- If there are spoons remaining on both sides, they will take the spoon on the side of their dominant hand.
- Otherwise, they do nothing.
You are also given a string of length consisting of L
, R
, and ?
. Among the possible combinations of dominant hands, find how many satisfy all of the following conditions, modulo :
- If the -th character of is
L
, person is left-handed. - If the -th character of is
R
, person is right-handed. - When everyone has finished acting, everyone has taken a spoon.
Constraints
- All input values are integers.
- is a permutation of .
- is a string of length consisting of
L
,R
, and?
.
Input
The input is given from Standard Input in the following format:
Output
Print the answer in a single line.
Sample Input 1
3
1 2 3
L??
Sample Output 1
2
When persons , , and are left-handed, left-handed, and right-handed, respectively, the actions are performed as follows:
- Person starts acting. There are spoons on both sides, so person takes spoon on the left side, which is the same as their dominant hand.
- Person starts acting. There are spoons on both sides, so person takes spoon on the left side, which is the same as their dominant hand.
- Person starts acting. There is no spoon on the right side, but spoon is remaining on the left side, so they take spoon . Everyone has finished acting and taken a spoon.
This combination of dominant hands satisfies the conditions. Besides, the conditions are also satisfied when persons are all left-handed.
Sample Input 2
3
1 3 2
R?L
Sample Output 2
0
No combinations of dominant hands satisfy the conditions.
Sample Input 3
12
6 2 9 3 1 4 11 5 12 10 7 8
????????????
Sample Output 3
160