CF1709C.Recover an RBS

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence (or, shortly, an RBS) 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 (the resulting expressions are: "(1)+(1)" and "((1+1)+1)");
  • bracket sequences ")(", "(" and ")" are not.

There was an RBS. Some brackets have been replaced with question marks. Is it true that there is a unique way to replace question marks with brackets, so that the resulting sequence is an RBS?

括号序列是指仅由字符 ( 和 ) 组成的字符串。正则括号序列(简称 RBS)是一种括号序列,它可以通过在原序列的字符之间插入字符 1 和 +,从而转化为一个合法的算术表达式。例如:

  • 括号序列 "()()" 和 "(())" 是正则的(得到的表达式分别为:"(1)+(1)" 和 "((1+1)+1)");
  • 括号序列 ")(", "(" 和 ")" 则不是。

现有一个 RBS,其中部分括号已被替换为问号 ?。是否存在唯一一种将问号替换为括号的方式,使得最终得到的序列是一个 RBS?

输入格式

The first line contains a single integer tt (1≤t≤5⋅1041 \le t \le 5 \cdot 10^4) — the number of testcases.

The only line of each testcase contains an RBS with some brackets replaced with question marks. Each character is either '(', ')' or '?'. At least one RBS can be recovered from the given sequence.

The total length of the sequences over all testcases doesn't exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤5⋅1041 \le t \le 5 \cdot 10^4)—— 测试用例的数量。

每个测试用例仅有一行,包含一个括号序列,其中部分括号被替换为问号。每个字符为 '('、')' 或 '?' 中的一个。给定序列至少可恢复出一个合法括号序列(RBS)。

所有测试用例中序列的总长度不超过 2⋅1052 \cdot 10^5。

输出格式

For each testcase, print "YES" if the way to replace question marks with brackets, so that the resulting sequence is an RBS, is unique. If there is more than one way, then print "NO".

对于每个测试用例,如果将问号替换为括号,使得得到的序列是一个正则括号序列(RBS)的方式是唯一的,则输出 "YES";如果存在多种方式,则输出 "NO"。

输入输出样例

  • 输入#1

    5
    (?))
    ??????
    ()
    ??
    ?(?)()?)

    输出#1

    YES
    NO
    YES
    YES
    NO

说明/提示

In the first testcase, the only possible original RBS is "(())".

In the second testcase, there are multiple ways to recover an RBS.

In the third and the fourth testcases, the only possible original RBS is "()".

In the fifth testcase, the original RBS can be either "((()()))" or "(())()()".

在第一个测试用例中,唯一可能的原始正则括号序列(RBS)是 "(())"。

在第二个测试用例中,存在多种方式恢复一个 RBS。

在第三个和第四个测试用例中,唯一可能的原始 RBS 是 "()"。

在第五个测试用例中,原始 RBS 可以是 "((()()))" 或 "(())()()"。

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

首页