CF749C.Voting

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote.

Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions on what should be the outcome of the vote. The voting procedure is rather complicated:

  1. Each of n employees makes a statement. They make statements one by one starting from employees 1 and finishing with employee n. If at the moment when it's time for the i-th employee to make a statement he no longer has the right to vote, he just skips his turn (and no longer takes part in this voting).
  2. When employee makes a statement, he can do nothing or declare that one of the other employees no longer has a right to vote. It's allowed to deny from voting people who already made the statement or people who are only waiting to do so. If someone is denied from voting he no longer participates in the voting till the very end.
  3. When all employees are done with their statements, the procedure repeats: again, each employees starting from 1 and finishing with n who are still eligible to vote make their statements.
  4. The process repeats until there is only one employee eligible to vote remaining and he determines the outcome of the whole voting. Of course, he votes for the decision suitable for his fraction.

You know the order employees are going to vote and that they behave optimal (and they also know the order and who belongs to which fraction). Predict the outcome of the vote.

在替代蛋糕制造公司(ACM)中有 nn 名员工。他们正在对某个极其重要的问题进行投票,而全球主流媒体正试图预测此次投票的结果。

每名员工属于两个派别之一:“德普利堪”(depublicans)或“雷莫克拉特”(remocrats),这两个派别对投票结果应为何种意见持完全相反的立场。投票流程较为复杂:

  1. nn 名员工依次发表声明,顺序为从第 11 号员工开始,至第 nn 号员工结束。当轮到第 ii 号员工发表声明时,若他已丧失投票权,则直接跳过其回合(此后不再参与本次投票)。
  2. 员工在发表声明时,可选择不采取任何行动,也可宣布某位其他员工丧失投票权。被剥夺投票权的对象可以是已经发表过声明的员工,也可以是尚未发表声明、仍在等待的员工。一旦某人被剥夺投票权,他将不再参与后续所有投票环节,直至整个流程彻底结束。
  3. 当所有员工均完成本轮声明后,流程重新开始:仍具备投票资格的员工再次按编号从 11 到 nn 的顺序依次发表声明。
  4. 此过程不断重复,直至仅剩一名具备投票资格的员工为止;该员工最终决定整个投票的结果。显然,他将投票支持符合其所属派别利益的决策。

你已知员工的发言顺序,且所有员工均以最优策略行事(他们彼此也清楚发言顺序及每位员工所属的派别)。请预测本次投票的最终结果。

输入格式

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of employees.

The next line contains n characters. The i-th character is 'D' if the i-th employee is from depublicans fraction or 'R' if he is from remocrats.

输入的第一行包含一个整数 nn(1≤n≤200 0001 \leq n \leq 200\,000)—— 表示员工人数。

下一行包含 nn 个字符。第 ii 个字符为 'D' 表示第 ii 位员工属于民主党派(depublicans),为 'R' 表示其属于共和党派(remocrats)。

输出格式

Print 'D' if the outcome of the vote will be suitable for depublicans and 'R' if remocrats will win.

如果投票结果对德共和党有利,则输出 'D';如果瑞莫克党获胜,则输出 'R'。

输入输出样例

  • 输入#1

    5
    DDRRR

    输出#1

    D
  • 输入#2

    6
    DDRRRR

    输出#2

    R

说明/提示

Consider one of the voting scenarios for the first sample:

  1. Employee 1 denies employee 5 to vote.
  2. Employee 2 denies employee 3 to vote.
  3. Employee 3 has no right to vote and skips his turn (he was denied by employee 2).
  4. Employee 4 denies employee 2 to vote.
  5. Employee 5 has no right to vote and skips his turn (he was denied by employee 1).
  6. Employee 1 denies employee 4.
  7. Only employee 1 now has the right to vote so the voting ends with the victory of depublicans.

考虑第一个样例中的一个投票情形:

  1. 员工 1 否决员工 5 的投票权。
  2. 员工 2 否决员工 3 的投票权。
  3. 员工 3 没有投票权,跳过本轮(他被员工 2 否决)。
  4. 员工 4 否决员工 2 的投票权。
  5. 员工 5 没有投票权,跳过本轮(他被员工 1 否决)。
  6. 员工 1 否决员工 4 的投票权。
  7. 此时仅有员工 1 拥有投票权,因此投票结束,共和党人获胜。

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

首页