IBMOA #45
Is Convertible Data
Estimated MediumJudge-ready
Topics (AI-labelled)StringsStacks & Heaps
For each string, you may take at most one parenthesis out of its position and insert it at any position; determine whether the string can become an ordinary valid parenthesis string. Not moving anything is allowed. Output 1 or 0.
Input
The first line contains n, followed by n lines of parenthesis strings. 1≤n≤200000, each string has length 1..200000, the total length is ≤200000, and only left and right parentheses appear.
Output
Output n values, each 0 or 1, in the same order as the input strings.
Example 1
Input:
3
)(
()
))((
Output:
1 1 0
Example 2
Input:
2
(()
())
Output:
0 0
Example 3
Input:
2
())(
()()
Output:
1 1
Example notes
The examples give 1 1 0; 0 0; and 1 1 respectively.
Editorial
Loading solution…