CF1610G.AmShZ Wins a Bet

NOI/NOI+/CTSC

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Right before the UEFA Euro 2020, AmShZ and Safar placed bets on who'd be the champion, AmShZ betting on Italy, and Safar betting on France.

Of course, AmShZ won. Hence, Safar gave him a bracket sequence SS. Note that a bracket sequence is a string made of '(' and ')' characters.

AmShZ can perform the following operation any number of times:

  • First, he cuts his string SS into three (possibly empty) contiguous substrings A,BA, B and CC. Then, he glues them back by using a '(' and a ')' characters, resulting in a new string SS = AA + "(" + BB + ")" + CC.

    For example, if SS = "))((" and AmShZ cuts it into AA = "", BB = "))", and CC = "((", He will obtain SS = "()))((" as a new string.

After performing some (possibly none) operations, AmShZ gives his string to Keshi and asks him to find the initial string. Of course, Keshi might be able to come up with more than one possible initial string. Keshi is interested in finding the lexicographically smallest possible initial string.

Your task is to help Keshi in achieving his goal.

A string aa is lexicographically smaller than a string bb if and only if one of the following holds:

  • aa is a prefix of bb, but a≠ba \ne b;
  • in the first position where aa and bb differ, the string aa has a letter that appears earlier in the alphabet than the corresponding letter in bb.

在欧洲杯2020开赛前,AmShZ 和 Safar 就谁将夺冠下了赌注:AmShZ 押意大利,Safar 押法国。

当然,AmShZ 赢了。因此,Safar 给了他一个括号序列 SS。注意,括号序列是由字符 '(' 和 ')' 构成的字符串。

AmShZ 可以执行以下操作任意多次:

  • 首先,他将字符串 SS 切割为三个(可能为空的)连续子串 AA、BB 和 CC;然后,他在 AA 和 CC 之间插入一对括号,即用 '(' 和 ')' 将它们连接起来,从而得到新字符串 S=A+“(”+B+“)”+CS = A + \text{``(''} + B + \text{``)''} + C。

    例如,若 S="))(("S = \text{"))(("},AmShZ 将其切分为 A=“”A = \text{``''}(空串)、B="))"B = \text{"))"}、C="(("C = \text{"(("},则他将得到新字符串 S=")))(("S = \text{")))(("}。

在执行若干次(可能为零次)上述操作后,AmShZ 将所得字符串交给 Keshi,并请他还原出原始字符串。当然,Keshi 可能还原出多个合法的初始字符串。Keshi 感兴趣的是找出字典序最小的可能初始字符串。

你的任务是帮助 Keshi 实现这一目标。

字符串 aa 的字典序小于字符串 bb,当且仅当满足下列条件之一:

  • aa 是 bb 的真前缀(即 aa 是 bb 的前缀但 a≠ba \ne b);
  • 在 aa 与 bb 首次出现不同字符的位置上,aa 中该位置的字符在字母表中早于 bb 中对应位置的字符。

输入格式

The only line of input contains a single string SS — the string after the operations (1≤∣S∣≤3⋅105)(1\le |S|\le 3 \cdot 10^5).

It is guaranteed that the first character of SS is ')'.

输入仅有一行,包含一个字符串 SS —— 经过操作后的字符串(1≤∣S∣≤3⋅1051\le |S|\le 3 \cdot 10^5)。

保证 SS 的第一个字符为 ')'。

输出格式

Print the lexicographically smallest possible initial string before operations.

输出操作前字典序最小的可能初始字符串。

输入输出样例

  • 输入#1

    )(()(())))

    输出#1

    )((())))

说明/提示

In the first sample, you can transform ")((())))" into ")(()(())))" by splitting it into ")(", empty string, and "(())))". It can be shown that this is the lexicographically smallest possible initial string

在第一个样例中,你可以将 ")((())))" 拆分为 ")("、空字符串和 "(())))",从而将其变换为 ")(()(())))"。可以证明,这是字典序最小的可能初始字符串。

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

首页