QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 256 MB 満点: 100 ハック可能 ✓

#11761. 跳石子

統計

有 $n$ 块石头排成一排,每块石头上标记着 $L$ 或 $R$。你可以从一块 $L$ 石头跳到它左侧的任意石头上,也可以从一块 $R$ 石头跳到它右侧的任意石头上。

更正式地说,对于位置在 $1 \le i \le n$ 的石头,如果它标记为 $L$,你可以跳到满足 $1 \le j < i$ 的任意石头 $j$ 上;如果它标记为 $R$,你可以跳到满足 $i < j \le n$ 的任意石头 $j$ 上。

你的目标是找到一个跳跃序列,使得你恰好访问每一块石头一次。如果你可以从任意选择的石头开始,这是否可能实现?

一个从第二块石头开始,访问每一块石头一次的有效路径示例

输入格式

输入的第一行包含一个整数 $t$ ($1 \le t \le 10^4$),表示测试用例的数量。接下来是各测试用例的描述。

每个测试用例的第一行包含一个整数 $n$ ($1 \le n \le 2 \cdot 10^5$),表示石头的数量。

每个测试用例的下一行包含一个长度为 $n$ 的字符串 $s$,由字符 $L$ 和 $R$ 组成,表示第 $i$ 块石头标记为 $L$ 或 $R$。

保证所有测试用例的 $n$ 之和不超过 $2 \cdot 10^5$。

输出格式

对于每个测试用例,如果可能实现,打印 “YES”(不含引号),否则打印 “NO”(不含引号)。

你可以以任何大小写形式打印每个字母(例如,字符串 “yEs”、“yes”、“Yes” 和 “YES” 都将被识别为肯定回答)。

样例

输入 1

7
6
LRRLRL
1
L
2
RL
2
LR
5
RRRRL
10
LRLRLRLRLR
31
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL

输出 1

YES
YES
YES
NO
YES
NO
YES

说明

在第二个样例中,$n = 1$,因此你可以从第一块石头开始,此时你已经访问了所有石头并完成了路径。

在第四个样例中,可以证明不存在有效的路径。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.