CF1776G.Another Wine Tasting Event

提高+/省选-

通过率:0%

时间限制:0.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

After the first successful edition, Gabriella has been asked to organize a second wine tasting event. There will be 2n−12n - 1 bottles of wine arranged in a row, each of which is either red wine or white wine.

This time, Gabriella has already chosen the type and order of all the bottles. The types of the wines are represented by a string ss of length 2n−12n - 1. For each 1≤i≤2n−11 \le i \le 2n - 1, it holds that si=Rs_i = \texttt{R} if the ii-th bottle is red wine, and si=Ws_i = \texttt{W} if the ii-th bottle is white wine.

Exactly nn critics have been invited to attend. The critics are numbered from 11 to nn. Just like last year, each critic jj wants to taste an interval of wines, that is, the bottles at positions aj, aj+1, …, bja_j, \, a_j + 1, \, \dots, \, b_j for some 1≤aj≤bj≤2n−11 \le a_j \le b_j \le 2n - 1. Moreover, they have the following additional requirements:

  • each of them wants to taste at least nn wines, that is, it must hold that bj−aj+1≥nb_j - a_j + 1 \ge n;
  • no two critics must taste exactly the same wines, that is, if j≠kj \ne k it must hold that aj≠aka_j \ne a_k or bj≠bkb_j \ne b_k.

Gabriella knows that, since the event is held in a coastal region of Italy, critics are especially interested in the white wines, and don't care much about the red ones. (Indeed, white wine is perfect to accompany seafood.) Thus, to ensure fairness, she would like that all critics taste the same number of white wines.

Help Gabriella find an integer xx (with 0≤x≤2n−10 \le x \le 2n - 1) such that there exists a valid assignment of intervals to critics where each critic tastes exactly xx white wines. It can be proved that at least one such xx always exists.

在首届活动圆满成功之后,加布里埃拉被邀请组织第二届品酒会。届时将有 2n−12n - 1 瓶葡萄酒排成一列,每瓶均为红葡萄酒或白葡萄酒。

本次,加布里埃拉已预先确定了所有酒瓶的种类及其排列顺序。葡萄酒种类由一个长度为 2n−12n - 1 的字符串 ss 表示。对每个 1≤i≤2n−11 \le i \le 2n - 1,若第 ii 瓶为红葡萄酒,则 si=Rs_i = \texttt{R};若为白葡萄酒,则 si=Ws_i = \texttt{W}。

恰好有 nn 位品酒师受邀出席。品酒师编号为 11 至 nn。与去年一样,每位品酒师 jj 希望品尝一段连续区间的葡萄酒,即位置为 aj, aj+1, …, bja_j,\, a_j + 1,\, \dots,\, b_j 的酒瓶,其中 1≤aj≤bj≤2n−11 \le a_j \le b_j \le 2n - 1。此外,他们还有以下额外要求:

  • 每位品酒师至少要品尝 nn 瓶葡萄酒,即必须满足 bj−aj+1≥nb_j - a_j + 1 \ge n;
  • 任意两位品酒师品尝的葡萄酒区间不能完全相同,即若 j≠kj \ne k,则必有 aj≠aka_j \ne a_k 或 bj≠bkb_j \ne b_k。

加布里埃拉知道,由于本次活动在意大利沿海地区举办,品酒师们尤其偏爱白葡萄酒,而对红葡萄酒兴趣不大(事实上,白葡萄酒是搭配海鲜的绝佳选择)。因此,为确保公平性,她希望每位品酒师品尝到的白葡萄酒数量完全相同。

请帮助加布里埃拉找出一个整数 xx(满足 0≤x≤2n−10 \le x \le 2n - 1),使得存在一种对品酒师分配区间的合法方案,使得每位品酒师恰好品尝 xx 瓶白葡萄酒。可以证明:这样的 xx 至少存在一个。

输入格式

The first line contains the integer nn (1≤n≤1061 \le n \le 10^6) — where 2n−12n - 1 is the number of bottles, and nn is the number of critics.

The second line contains a string ss of length 2n−12n - 1 that represents the arrangement of the wines — the ii-th character of ss (1≤i≤2n−11 \le i \le 2n - 1) is R\texttt{R} for a red wine and W\texttt{W} for a white wine.

第一行包含一个整数 nn(1≤n≤1061 \le n \le 10^6)——其中 2n−12n - 1 表示酒瓶总数,nn 表示品酒师人数。

第二行包含一个长度为 2n−12n - 1 的字符串 ss,表示葡萄酒的排列方式——字符串 ss 的第 ii 个字符(1≤i≤2n−11 \le i \le 2n - 1)为 R\texttt{R} 表示红葡萄酒,为 W\texttt{W} 表示白葡萄酒。

输出格式

Print an integer xx — the number of white wines that each critic will taste.

It can be proved that at least one solution exists. If multiple solutions exist, any of them will be accepted.

输出一个整数 xx —— 每位品酒师将品尝的白葡萄酒数量。

可以证明至少存在一个解。若存在多个解,则其中任意一个均可接受。

输入输出样例

  • 输入#1

    5
    RWWRRRWWW

    输出#1

    2
  • 输入#2

    1
    R

    输出#2

    0

说明/提示

In the first sample, there are 55 critics and 2⋅5−1=92 \cdot 5 - 1 = 9 bottles of wine. A possible set of intervals that makes each critic taste 22 white wines is the following: [2,6],[2, 6], [1,6],[1, 6], [4,8],[4, 8], [1,5],[1, 5], [3,7][3, 7]. Note that all intervals contain at least 55 bottles.

In the second sample, there is 11 critic and 2⋅1−1=12 \cdot 1 - 1 = 1 bottle of wine. The only possible interval is [1,1][1, 1], which gives x=0x = 0.

在第一个样例中,有 55 位评论家和 2⋅5−1=92 \cdot 5 - 1 = 9 瓶葡萄酒。一种使得每位评论家恰好品尝 22 种白葡萄酒的区间集合如下:[2,6],[2, 6], [1,6],[1, 6], [4,8],[4, 8], [1,5],[1, 5], [3,7][3, 7]。注意,所有区间均至少包含 55 瓶酒。

在第二个样例中,有 11 位评论家和 2⋅1−1=12 \cdot 1 - 1 = 1 瓶葡萄酒。唯一可能的区间是 [1,1][1, 1],此时 x=0x = 0。

输入解题思路,AI测评打分。不知道怎么写?

首页