A9669 | Arthur and Brackets
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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!
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}<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.
Next $n$ lines contain numbers $l_{i}$ and $r_{i}$ ( $1<=l_{i}<=r_{i}<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).
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
(())()
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted