CF1860A.Not a Substring

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

A bracket sequence is a string consisting of characters '(' and/or ')'. A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters '1' and '+' between the original characters of the sequence. For example:

  • bracket sequences "()()" and "(())" are regular (they can be transformed into "(1)+(1)" and "((1+1)+1)", respectively);
  • bracket sequences ")(", "(" and ")" are not regular.

You are given a bracket sequence ss ; let's define its length as nn . Your task is to find a regular bracket sequence tt of length 2n2n such that ss does not occur in tt as a contiguous substring, or report that there is no such sequence.

输入格式

The first line contains a single integer tt ( 1t10001 \le t \le 1000 ) — the number of test cases.

The only line of each test case contains a string ss ( 2s502 \le |s| \le 50 ), consisting of characters "(" and/or ")".

输出格式

For each test case, print the answer to it. If there is no required regular bracket sequence, print NO in a separate line. Otherwise, print YES in the first line, and the required regular bracket sequence tt itself in the second line. If there are multiple answers — you may print any of them.

输入输出样例

  • 输入#1

    4
    )(
    (()
    ()
    ))()

    输出#1

    YES
    (())
    YES
    ()()()
    NO
    YES
    ()(()())
首页