博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #288 (Div. 2) E. Arthur and Brackets 贪心
阅读量:6941 次
发布时间:2019-06-27

本文共 2752 字,大约阅读时间需要 9 分钟。

E. Arthur and Brackets
time limit per test
2 seconds
memory limit per test
128 megabytes
input
standard input
output
standard output

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 [li, ri], 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 [li, ri].

Help Arthur restore his favorite correct bracket sequence!

Input

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 li and ri (1 ≤ li ≤ ri < 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.

Output

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

Sample test(s)
Input
4 1 1 1 1 1 1 1 1
Output
()()()()
Input
3 5 5 3 3 1 1
Output
((()))
Input
3 5 5 3 3 2 2
Output
IMPOSSIBLE
Input
3 2 3 1 4 1 4
Output
(())()
#include
#include
#include
using namespace std;int l[1000], r[1000];vector
v;string s;int main(){ int n; cin >> n; for(int i = 0; i < n; i++) { cin >> l[i] >> r[i]; s += '('; v.push_back(i); while(v.size() && l[v.back()] <= 1) { int x = v.back(); if(r[x] < 1) { cout << "IMPOSSIBLE" << endl; return 0; } for(int i = 0; i < v.size(); i++) l[v[i]] -= 2, r[v[i]] -= 2; s += ')'; v.pop_back(); } } if(v.size()) cout << "IMPOSSIBLE" << endl; else cout << s << endl; return 0;}

 

转载地址:http://okinl.baihongyu.com/

你可能感兴趣的文章
subprocess模块
查看>>
大数据入门基础系列之初步认识大数据生态系统圈(博主推荐)
查看>>
linux下命令行的查找顺序
查看>>
基于HTML5 Canvas 点击添加 2D 3D 机柜模型
查看>>
详述 SQL 中的 distinct 和 row_number() over() 的区别及用法
查看>>
xshell 登陆堡垒机实现自动跳转
查看>>
Hexo-设置阅读全文
查看>>
实模式与保护模式
查看>>
分布式ID生成器解决方案
查看>>
ResolveUrl in external JavaScript file in asp.net project
查看>>
EL表达式JSON应用
查看>>
人民邮电出版社图灵公司征求《Windows Communication Foundation Unleashed》译者
查看>>
使用pidstat查看进程资源使用情况
查看>>
PatternsInJava文摘
查看>>
理解SVN关键词BASE,HEAD,COMMITTED,PREV
查看>>
AOP 实现的原理简析
查看>>
linux命令汇总1
查看>>
PHP 初学
查看>>
I.MX6 U-boot编译找不到用户目录
查看>>
date 修改系统时间
查看>>