CF1023C.Bracket Subsequence
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A bracket sequence is a string containing only characters "(" and ")". 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 (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.
Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
You are given a regular bracket sequence s and an integer number k. Your task is to find a regular bracket sequence of length exactly k such that it is also a subsequence of s.
It is guaranteed that such sequence always exists.
括号序列是指仅由字符 ( 和 ) 组成的字符串。正则括号序列(regular bracket sequence)是一种括号序列,它可以通过在原序列的字符之间插入字符 1 和 +,从而转化为一个合法的算术表达式。例如,括号序列 "()()" 和 "(())" 是正则的(对应的表达式分别为 "(1)+(1)" 和 "((1+1)+1)"),而 ")(", "(" 和 ")" 则不是。
子序列(subsequence)是指从另一个序列中删除若干元素(可以是零个)后,不改变剩余元素相对顺序所得到的序列。
给定一个正则括号序列 s 和一个整数 k。你的任务是找出一个长度恰好为 k 的正则括号序列,且该序列同时是 s 的子序列。
题目保证这样的序列一定存在。
输入格式
The first line contains two integers n and k (2≤k≤n≤2⋅105, both n and k are even) — the length of s and the length of the sequence you are asked to find.
The second line is a string s — regular bracket sequence of length n.
第一行包含两个整数 n 和 k(2≤k≤n≤2⋅105,且 n 和 k 均为偶数)—— 分别表示字符串 s 的长度以及所要求的子序列的长度。
第二行为一个字符串 s —— 长度为 n 的合法括号序列。
输出格式
Print a single string — a regular bracket sequence of length exactly k such that it is also a subsequence of s.
It is guaranteed that such sequence always exists.
输出一个字符串——该字符串是一个长度恰好为 k 的合法括号序列,且它也是 s 的一个子序列。
保证这样的序列一定存在。
输入输出样例
输入#1
6 4 ()(())
输出#1
()()
输入#2
8 8 (()(()))
输出#2
(()(()))
输入解题思路,AI测评打分。不知道怎么写?