CF1776G.Another Wine Tasting Event

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

After the first successful edition, Gabriella has been asked to organize a second wine tasting event. There will be 2n12n - 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 2n12n - 1 . For each 1i2n11 \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 1ajbj2n11 \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 bjaj+1nb_j - a_j + 1 \ge n ;
  • no two critics must taste exactly the same wines, that is, if jkj \ne k it must hold that ajaka_j \ne a_k or bjbkb_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 0x2n10 \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.

输入格式

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

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

输出格式

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.

输入输出样例

  • 输入#1

    5
    RWWRRRWWW

    输出#1

    2
  • 输入#2

    1
    R

    输出#2

    0

说明/提示

In the first sample, there are 55 critics and 251=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 211=12 \cdot 1 - 1 = 1 bottle of wine. The only possible interval is [1,1][1, 1] , which gives x=0x = 0 .

首页