Stone Jump

시간 제한1초메모리 제한2048 MB

요약
L 또는 R로 표시된 돌들이 일렬로 놓여 있을 때, 아무 돌에서나 시작해 L은 왼쪽, R은 오른쪽으로만 점프하며 모든 돌을 정확히 한 번씩 방문할 수 있는지 판별한다.
난이도

보통10점 중 4점

유형
그리디, 구현
정답자
아직 제출이 없습니다

문제

There are nn stones in a row, each marked with LL or RR. You can jump from an LL stone to any stone to its left, and from an RR stone to any stone to its right.

More formally, for a stone at position 1≤i≤n1 \le i \le n, if it is marked with LL, you can jump to any stone jj where 1≤j<i1 \le j < i, and if it is marked with RR, you can jump to any stone jj where i<j≤ni < 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 tt (1≤t≤1041 \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 nn (1≤n≤2⋅1051 \le n \le 2\cdot 10^5) --- the number of stones.

The next line of each test case contains a string ss consisting of nn characters L and R, indicating whether stone ii is marked with LL or RR.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052\cdot 10^5.

출력

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

힌트

In the second sample case, n=1n=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.

예제1

  1. 예제 1

    입력
    7
    6
    LRRLRL
    1
    L
    2
    RL
    2
    LR
    5
    RRRRL
    10
    LRLRLRLRLR
    31
    LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
    
    예상 출력
    YES
    YES
    YES
    NO
    YES
    NO
    YES