CF1860A.Not a Substring
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
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 s; let's define its length as n. Your task is to find a regular bracket sequence t of length 2n such that s does not occur in t as a contiguous substring, or report that there is no such sequence.
括号序列是由字符 '(' 和/或 ')' 组成的字符串。正则括号序列(regular bracket sequence)是指:通过在原序列的字符之间插入字符 '1' 和 '+',可将其转化为一个合法的算术表达式的括号序列。例如:
- 括号序列
"()()"和"(())"是正则的(它们可分别转化为"(1)+(1)"和"((1+1)+1)"); - 括号序列
")(","("和")"不是正则的。
给定一个括号序列 s;设其长度为 n。你的任务是:构造一个长度为 2n 的正则括号序列 t,使得 s 不作为连续子串出现在 t 中;若不存在这样的序列,则报告无解。
输入格式
The first line contains a single integer t (1≤t≤1000) — the number of test cases.
The only line of each test case contains a string s (2≤∣s∣≤50), consisting of characters "(" and/or ")".
第一行包含一个整数 t(1≤t≤1000)——测试用例的数量。
每个测试用例仅有一行,包含一个字符串 s(2≤∣s∣≤50),由字符 "(" 和/或 ")" 组成。
输出格式
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 t itself in the second line. If there are multiple answers — you may print any of them.
对于每个测试用例,输出其答案。如果不存在所要求的合法括号序列,则在单独一行中输出 NO。否则,在第一行输出 YES,在第二行输出所要求的合法括号序列 t 本身。如果存在多个满足条件的答案,你可以输出其中任意一个。
输入输出样例
输入#1
4 )( (() () ))()
输出#1
YES (()) YES ()()() NO YES ()(()())
输入解题思路,AI测评打分。不知道怎么写?