Brackets
Time limit1sMemory limit512 MB
Each value's two positions must both be '(' or both be ')' so the result is a valid bracket sequence. Print the lexicographically smallest one, or the sad smiley if none exists.
- Level
Medium7 of 10
- Topics
- Greedy, Segment tree, String
- Solved
- No attempts yet
Problem
There are elements divided into pairs.
For each pair, you must assign an opening bracket to both elements, or a closing bracket to both elements. The resulting bracket sequence must be a correct bracket sequence. If that is impossible, report it. If several assignments work, output the lexicographically smallest resulting string, where '(' is smaller than ')'.
Input
The first line contains one integer ().
The next line contains integers (). Each integer from to appears exactly twice in this sequence.
Output
If no valid assignment exists, print '(' (the Russian sad smiley). Otherwise, print the lexicographically smallest correct bracket sequence of length .