302621: CF508E. Arthur and Brackets

Memory Limit:128 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Arthur and Brackets

题意翻译

一个长为2n的括号序列,左括号和右括号都是n个。 对于从左到右的第i个左括号,对与其配对的右括号有如下限制: 与其配对的右括号和这个左括号之间的距离需要在 [ Li , Ri ] 之间。 输入的第一行给出n(1<=n<=600)。 之后的n行,给出限制:Li、Ri。 如果满足限制的括号序列存在,输出任意一个即可。 否则输出"IMPOSSIBLE"(不包含引号)。

题目描述

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 $ 2n $ . 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!

输入输出格式

输入格式


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}&lt;2n $ ), 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.

输出格式


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).

输入输出样例

输入样例 #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

(())()

Input

题意翻译

一个长为2n的括号序列,左括号和右括号都是n个。 对于从左到右的第i个左括号,对与其配对的右括号有如下限制: 与其配对的右括号和这个左括号之间的距离需要在 [ Li , Ri ] 之间。 输入的第一行给出n(1<=n<=600)。 之后的n行,给出限制:Li、Ri。 如果满足限制的括号序列存在,输出任意一个即可。 否则输出"IMPOSSIBLE"(不包含引号)。

加入题单

上一题 下一题 算法标签: