#P6000. [CEOI 2016] match
[CEOI 2016] match
Description
You are given a string consisting of lowercase letters. You need to construct a lexicographically smallest (assume the left parenthesis is lexicographically smaller than the right parenthesis) valid parenthesis sequence that matches this string.
A string and a parenthesis sequence are defined to match as follows: first, their lengths must be equal; second, for every pair of matched left and right parentheses at positions , it must hold that .
If there is no solution, output -1.
Input Format
One line containing a string .
Output Format
One line containing a parenthesis sequence, or -1.
abbaaa
(()())
Hint
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号