CF508E.Arthur and Brackets
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:128MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Notice that the memory limit is non-standard.
Recently Arthur and Sasha have studied correct bracket sequences. Arthur understood this topic perfectly and become so amazed about correct bracket sequences, so he even got himself a favorite correct bracket sequence of length 2_n_. Unlike Arthur, Sasha understood the topic very badly, and broke Arthur's favorite correct bracket sequence just to spite him.
All Arthur remembers about his favorite sequence is for each opening parenthesis ('(') the approximate distance to the corresponding closing one (')'). For the i-th opening bracket he remembers the segment [l__i, r__i], containing the distance to the corresponding closing bracket.
Formally speaking, for the i-th opening bracket (in order from left to right) we know that the difference of its position and the position of the corresponding closing bracket belongs to the segment [l__i, r__i].
Help Arthur restore his favorite correct bracket sequence!
注意:本题的内存限制为非标准限制。
最近,Arthur 和 Sasha 学习了“合法括号序列”(correct bracket sequences)。Arthur 完全掌握了这一知识点,并对合法括号序列感到无比着迷,甚至为自己构造了一个长度为 2n 的最喜爱的合法括号序列。与 Arthur 不同,Sasha 对该知识点理解得非常差,为了故意气 Arthur,他把 Arthur 最喜爱的合法括号序列弄坏了。
Arthur 对自己最喜爱的序列仅记得:对每个左括号 '(',他大致记得其对应右括号 ')' 与它的距离区间。具体来说,对第 i 个左括号(从左到右编号),他记得其对应右括号与它的距离落在区间 [li,ri] 内。
形式化地讲,对第 i 个左括号(按从左到右顺序),我们知道:该左括号的位置与其对应右括号的位置之差属于区间 [li,ri]。
请帮助 Arthur 恢复他最喜爱的合法括号序列!
输入格式
The first line contains integer n (1 ≤ n ≤ 600), the number of opening brackets in Arthur's favorite correct bracket sequence.
Next n lines contain numbers l__i and r__i (1 ≤ l__i ≤ r__i < 2_n_), representing the segment where lies the distance from the i-th opening bracket and the corresponding closing one.
The descriptions of the segments are given in the order in which the opening brackets occur in Arthur's favorite sequence if we list them from left to right.
第一行包含一个整数 n(1≤n≤600),表示阿瑟最喜爱的合法括号序列中左括号的个数。
接下来的 n 行每行包含两个数 li 和 ri(1≤li≤ri<2n),表示第 i 个左括号与其对应右括号之间距离所在的区间。
这些区间的描述顺序,与阿瑟最喜爱的括号序列中左括号从左到右出现的顺序一致。
输出格式
If it is possible to restore the correct bracket sequence by the given data, print any possible choice.
If Arthur got something wrong, and there are no sequences corresponding to the given information, print a single line "IMPOSSIBLE" (without the quotes).
如果可以根据给定的数据恢复出正确的括号序列,则输出任意一个可能的解。
如果阿瑟弄错了,且不存在符合给定信息的序列,则输出一行 "IMPOSSIBLE"(不带引号)。
输入输出样例
输入#1
4 1 1 1 1 1 1 1 1
输出#1
()()()()
输入#2
3 5 5 3 3 1 1
输出#2
((()))
输入#3
3 5 5 3 3 2 2
输出#3
IMPOSSIBLE
输入#4
3 2 3 1 4 1 4
输出#4
(())()
输入解题思路,AI测评打分。不知道怎么写?