Logo
(追記) (追記ここまで)

33788번 - Stone Jump 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB52403676.596%

문제

There are $n$ stones in a row, each marked with $L$ or $R$. You can jump from an $L$ stone to any stone to its left, and from an $R$ stone to any stone to its right.

More formally, for a stone at position 1ドル \le i \le n,ドル if it is marked with $L,ドル you can jump to any stone $j$ where 1ドル \le j < i,ドル and if it is marked with $R,ドル you can jump to any stone $j$ where $i < j \le n$.

Your goal is to find a sequence of jumps such that you visit every stone exactly once. If you can start at any stone of your choice, is this possible?

One example of a valid path visiting each stone once, starting from the second stone

입력

The first line of the input contains a single integer $t$ (1ドル \le t \le 10^4$) --- the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer $n$ (1ドル \le n \le 2\cdot 10^5$) --- the number of stones.

The next line of each test case contains a string $s$ consisting of $n$ characters L and R, indicating whether stone $i$ is marked with $L$ or $R$.

It is guaranteed that the sum of $n$ over all test cases does not exceed 2ドル\cdot 10^5$.

출력

For each test case print "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise.

제한

예제 입력 1

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

예제 출력 1

YES
YES
YES
NO
YES
NO
YES

노트

In the second sample case, $n=1,ドル so you can start on the first stone, at which point you have visited all stones and completed your path.

In the fourth sample case, it can be shown that no valid path exists.

출처

University > Rutgers University > Rutgers University Programming Contest Spring 2025 B번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /