题库练习 Hall of Fame
← 上一题 下一题 →

A15572 | Hall of Fame

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Thalia is a Legendary Grandmaster in chess. She has $n$ trophies in a line numbered from $1$ to $n$ (from left to right) and a lamp standing next to each of them (the lamps are numbered as the trophies).

A lamp can be directed either to the left or to the right, and it illuminates all trophies in that direction (but not the one it is next to). More formally, Thalia has a string $s$ consisting only of characters 'L' and 'R' which represents the lamps' current directions. The lamp $i$ illuminates:

- trophies $1,2,\ldots, i-1$ if $s_i$ is 'L';
- trophies $i+1,i+2,\ldots, n$ if $s_i$ is 'R'.

She can perform the following operation at most once:

- Choose an index $i$ ( $1 \leq i < n$ );
- Swap the lamps $i$ and $i+1$ (without changing their directions). That is, swap $s_i$ with $s_{i+1}$ .

Thalia asked you to illuminate all her trophies (make each trophy illuminated by at least one lamp), or to tell her that it is impossible to do so. If it is possible, you can choose to perform an operation or to do nothing. Notice that lamps cannot change direction, it is only allowed to swap adjacent ones.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases $t$ ( $1 \leq t \leq 10\,000$ ). The description of the test cases follows.

The first line of each test case contains a positive integer $n$ ( $2 \leq n \leq 100\,000$ ) — the number of trophies.

The second line of each test case contains a string $s$ of length $n$ consisting only of characters 'L' and 'R' — the $i$ -th character describes the direction of the $i$ -th lamp.

It is guaranteed that the sum of $n$ over all test cases does not exceed $100\,000$ .

输出格式

For each test case print $-1$ if it is impossible to illuminate all trophies by performing one operation (or doing nothing). Otherwise, print $0$ if you choose not to perform the operation (i.e., the trophies are illuminated by the initial positioning of the lamps), or an index $i$ ( $1 \leq i < n$ ) if you choose to swap lamps $i$ and $i+1$ .

If there are multiple answers, print any.

输入输出样例

输入 #1
6
2
LL
2
LR
2
RL
2
RR
7
LLRLLLR
7
RRLRRRL
输出 #1
-1
1
0
-1
3
6
C++ 编辑器
输入
输出