QOJ.ac

QOJ

时间限制: 0.5 s 内存限制: 2048 MB 总分: 100

#5647. 又一次品酒活动

统计

在第一届成功举办之后,Gabriella 被邀请组织第二场品酒活动。 活动中将有 $2n - 1$ 瓶葡萄酒排成一排,每一瓶要么是红葡萄酒,要么是白葡萄酒。

这一次,Gabriella 已经选好了所有酒的种类和顺序。酒的种类由一个长度为 $2n - 1$ 的字符串 $s$ 表示。对于每个 $1 \le i \le 2n - 1$,如果第 $i$ 瓶是红葡萄酒,则 $s_i = \text{R}$;如果第 $i$ 瓶是白葡萄酒,则 $s_i = \text{W}$。

活动邀请了恰好 $n$ 位评论家参加,评论家编号为 $1$ 到 $n$。和去年一样,每位评论家 $j$ 都想品尝一段连续的葡萄酒,即位置在 $a_j, a_j+1, \dots, b_j$ 的酒,其中 $1 \le a_j \le b_j \le 2n - 1$。此外,他们还有以下附加要求: 每位评论家都想品尝至少 $n$ 瓶酒,即必须满足 $b_j - a_j + 1 \ge n$; 没有两位评论家品尝完全相同的酒,即如果 $j \neq k$,则必须满足 $a_j \neq a_k$ 或 $b_j \neq b_k$。

Gabriella 知道,由于活动在意大利沿海地区举行,评论家们对白葡萄酒特别感兴趣,而不太在意红葡萄酒。(事实上,白葡萄酒是搭配海鲜的绝佳选择。)因此,为了确保公平,她希望所有评论家品尝的白葡萄酒数量相同。

请帮助 Gabriella 找到一个整数 $x$(其中 $0 \le x \le 2n - 1$),使得存在一种合法的区间分配方案,让每位评论家恰好品尝到 $x$ 瓶白葡萄酒。可以证明,至少存在一个这样的 $x$。

输入格式

第一行包含整数 $n$ ($1 \le n \le 10^6$) —— 其中 $2n - 1$ 是酒的总数,$n$ 是评论家的数量。

第二行包含一个长度为 $2n - 1$ 的字符串 $s$,表示酒的排列 —— $s$ 的第 $i$ 个字符 ($1 \le i \le 2n - 1$) 为 $\text{R}$ 表示红葡萄酒,为 $\text{W}$ 表示白葡萄酒。

输出格式

输出一个整数 $x$ —— 每位评论家品尝的白葡萄酒数量。

可以证明至少存在一个解。如果存在多个解,输出其中任意一个即可。

样例

样例输入 1

5
RWWRRRWWW

样例输出 1

2

说明 1

共有 5 位评论家和 $2 \cdot 5 - 1 = 9$ 瓶酒。一种使每位评论家品尝 2 瓶白葡萄酒的区间分配方案如下:$[2, 6], [1, 6], [4, 8], [1, 5], [3, 7]$。注意所有区间都包含至少 5 瓶酒。

样例输入 2

1
R

样例输出 2

0

说明 2

共有 1 位评论家和 $2 \cdot 1 - 1 = 1$ 瓶酒。唯一可能的区间是 $[1, 1]$,这使得 $x = 0$。

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.