CF2210D.A Simple RBS Problem

提高+/省选-

通过率:0%

AC君温馨提醒

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

题目描述

A bracket sequence is called regular if it is possible to obtain a correct arithmetic expression by inserting characters $ + $ and $ 1 $ into this sequence. For example, sequences (())(), () and (()(())) are regular, while )(, (() and (()))( are not. Let's call a regular bracket sequence RBS.

You can perform the following operation on any RBS string $ b $ —

  • Choose any two disjoint, non empty substrings $ ^{\text{∗}} $ of $ b $ which are RBS and swap the two substrings.

More formally, let $ m $ be the length of $ b $ . You can perform the following operation on $ b $ :

  • Choose indices $ 1 \le l_1 \lt r_1 \lt l_2 \lt r_2 \le m $ such that the substrings $ b[{l_1..r_1}] $ and $ b[l_2..r_2] $ are both RBS and swap these substrings. The string $ b $ becomes $ b_1 \ldots b_{l_1-1} b_{l_2} b_{l_2+1}\ldots b_{r_2} b_{r_1+1}\ldots b_{l_2-1} b_{l_1} b_{l_1+1}\ldots b_{r_1}b_{r_2+1} \ldots b_m $ .

You are given two strings $ s $ and $ t $ of length $ n $ ( $ n $ is even) such that both $ s $ and $ t $ are RBS.

Determine whether you can transform $ s $ to $ t $ using the above operation any number of times.

$ ^{\text{∗}} $ A string $ a $ is a substring of a string $ b $ if $ a $ can be obtained from $ b $ by the deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 10^4 $ ). The description of the test cases follows.

The first line of each test case contains an integer $ n $ ( $ 4\leq n\leq 5\cdot 10^5 $ , $ n $ is even).

The second line of each test case contains a string $ s $ of length $ n $ such that $ s $ is an RBS.

The third line of each test case contains a string $ t $ of length $ n $ such that $ t $ is an RBS.

It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 5\cdot 10^5 $ .

输出格式

For each test case, print "YES" if $ s $ can be transformed to $ t $ , and "NO" otherwise.

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

输入输出样例

  • 输入#1

    5
    4
    ()()
    ()()
    4
    ()()
    (())
    6
    (())()
    ()(())
    8
    (()()())
    ()()(())
    8
    ()()(())
    ()(()())

    输出#1

    YES
    NO
    YES
    NO
    YES

说明/提示

In the first test case, the two strings are already same.

In the third test case, we can choose $ l_1=1,r_1=4,l_2=5,r_2=6 $ and transform $ s $ to $ t $ .

Here is a visualization of the operation performed in this case —

$ \color{red}{(())}\color{blue}{()}\rightarrow\color{blue}{()}\color{red}{(())} $

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

首页