The Ultimate Wine Tasting Event

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

요약
W가 n개, R이 n개인 문자열이 주어질 때, 두 부분집합을 골라 서로 대응하는 위치를 교환해 앞 n자리를 모두 W로 만들 수 있는지 판정한다.
난이도

쉬움10점 중 3점

유형
그리디, 문자열, 수학
정답자
아직 제출이 없습니다

문제

Rumors of the excellence of Gabriella’s wine tasting events have toured the world and made it to the headlines of prestigious wine magazines. Now, she has been asked to organize an event at the EUC 2025!

This time she selected 2n2n bottles of wine, of which exactly nn are of white wine, and exactly nn of red wine. She arranged them in a line as usual, in a predetermined order described by a string ss of length 2n2n: for 1≤i≤2n1 ≤ i ≤ 2n, the ii-th bottle from the left is white wine if s_i=s\_i = W and red wine if s_i=s\_i = R.

To spice things up for the attendees (which include EUC contestants), Gabriella came up with the following wine-themed problem:

Consider a way of dividing the 2n2n bottles into two disjoint subsets, each containing nn bottles. Then, for every 1≤i≤n1 ≤ i ≤ n, swap the ii-th bottle in the first subset (from the left) and the ii-th bottle of the second subset (also from the left). Is it possible to choose the subsets so that, after this operation is done exactly once, the white wines occupy the first nn positions?

입력

The first line contains an integer tt (1≤t≤5001 ≤ t ≤ 500) — the number of test cases. The descriptions of the tt test cases follow.

The first line of each test case contains an integer nn (1≤n≤1001 ≤ n ≤ 100) — where 2n2n is the total number of bottles.

The second line of each test case contains a string ss of length 2n2n, describing the bottle arrangement — the ii-th character of ss (1≤i≤2n1 ≤ i ≤ 2n) is W for a white wine and R for a red wine.

It is guaranteed that ss contains exactly nn W’s and nn R’s.

출력

For each test case, print YES if it is possible to divide the bottles as explained in the statement. Otherwise, print NO.

예제1

  1. 예제 1

    입력
    3
    4
    WRRWWWRR
    1
    WR
    20
    WWWWRRWRRRRRWRRWRWRRWRRWWWWWWWRWWRWWRRRR
    
    예상 출력
    YES
    NO
    YES