QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 2048 MB Total points: 100

#10319. The Ultimate Wine Tasting Event

الإحصائيات

Gabriella 的品酒活动因其卓越的品质而闻名世界,并登上了各大著名葡萄酒杂志的头条。现在,她受邀在 EUC 2025 上组织一场活动!

这一次,她挑选了 $2n$ 瓶葡萄酒,其中恰好有 $n$ 瓶白葡萄酒和 $n$ 瓶红葡萄酒。她像往常一样将它们排成一排,排列顺序由一个长度为 $2n$ 的字符串 $s$ 描述:对于 $1 \le i \le 2n$,若 $s_i = \text{W}$,则从左往右数第 $i$ 瓶为白葡萄酒;若 $s_i = \text{R}$,则为红葡萄酒。

为了给参加者(包括 EUC 的参赛选手)增添趣味,Gabriella 提出了以下与葡萄酒相关的问题:

考虑将这 $2n$ 瓶酒分成两个不相交的子集,每个子集包含 $n$ 瓶酒。然后,对于每个 $1 \le i \le n$,交换第一个子集中的第 $i$ 瓶酒(从左往右数)和第二个子集中的第 $i$ 瓶酒(从左往右数)。是否可以选择这两个子集,使得在进行一次这样的操作后,所有白葡萄酒恰好占据前 $n$ 个位置?

输入格式

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

每个测试用例的第一行包含一个整数 $n$ ($1 \le n \le 100$),其中 $2n$ 是葡萄酒的总数。

每个测试用例的第二行包含一个长度为 $2n$ 的字符串 $s$,描述了葡萄酒的排列方式——$s$ 的第 $i$ 个字符 ($1 \le i \le 2n$) 为 $\text{W}$ 表示白葡萄酒,为 $\text{R}$ 表示红葡萄酒。

保证 $s$ 中恰好包含 $n$ 个 $\text{W}$ 和 $n$ 个 $\text{R}$。

输出格式

对于每个测试用例,如果能够按照题目描述的方式划分葡萄酒,则输出 YES,否则输出 NO。

样例

输入 1

3
4
WRRWWWRR
1
WR
20
WWWWRRWRRRRRWRRWRWRRWRRWWWWWWWRWWRWWRRRR

输出 1

YES
NO
YES

说明

在第一个测试用例中,我们可以将位置 1, 2, 3, 7 处的瓶子(分别是:白、红、红、红)组成一个子集,将位置 4, 5, 6, 8 处的瓶子(分别是:白、白、白、红)组成另一个子集。然后我们交换配对 (1, 4), (2, 5), (3, 6) 和 (7, 8),操作完成后,白葡萄酒将占据前 4 个位置,红葡萄酒将占据后 4 个位置。

在第二个测试用例中,只有一种划分方式:一个子集包含第一瓶酒,另一个子集包含第二瓶酒。交换后,最终排列为 RW,因此没有解。

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.