| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 (추가 시간 없음) | 2048 MB | 33 | 22 | 19 | 65.517% |
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 2ドルn$ bottles of wine, of which exactly $n$ are of white wine, and exactly $n$ of red wine. She arranged them in a line as usual, in a predetermined order described by a string $s$ of length 2ドルn$: for 1ドル ≤ i ≤ 2n,ドル the $i$-th bottle from the left is white wine if $s_i = $W and red wine if $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 2ドルn$ bottles into two disjoint subsets, each containing $n$ bottles. Then, for every 1ドル ≤ i ≤ n,ドル swap the $i$-th bottle in the first subset (from the left) and the $i$-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 $n$ positions?
The first line contains an integer $t$ (1ドル ≤ t ≤ 500$) — the number of test cases. The descriptions of the $t$ test cases follow.
The first line of each test case contains an integer $n$ (1ドル ≤ n ≤ 100$) — where 2ドルn$ is the total number of bottles.
The second line of each test case contains a string $s$ of length 2ドルn,ドル describing the bottle arrangement — the $i$-th character of $s$ (1ドル ≤ i ≤ 2n$) is W for a white wine and R for a red wine.
It is guaranteed that $s$ contains exactly $n$ W’s and $n$ R’s.
For each test case, print YES if it is possible to divide the bottles as explained in the statement. Otherwise, print NO.
3 4 WRRWWWRR 1 WR 20 WWWWRRWRRRRRWRRWRWRRWRRWWWWWWWRWWRWWRRRR
YES NO YES
In the first test case, we can make one subset out of the bottles at positions 1ドル,ドル 2ドル,ドル 3ドル$ and 7ドル$ (which are, respectively: white, red, red, red) and the other subset out of the bottles at positions 4ドル,ドル 5ドル,ドル 6ドル,ドル 8ドル$ (which are, respectively: white, white, white, red). We will then swap pairs $(1, 4),ドル $(2, 5),ドル $(3, 6)$ and $(7, 8),ドル after which the white wines will occupy the first 4ドル$ positions, and the red wines the last 4ドル$ positions.
In the second test case, there is only one possible way to form the subsets: one with the first bottle, and one with the second bottle. After swapping, the resulting arrangement is RW, therefore there is no solution.