#P7269. [BalticOI 2005] Magic Parenthesis (Day1)

[BalticOI 2005] Magic Parenthesis (Day1)

Description

Given a string SS of length NN, consisting of (, ), and ].

There are MM ] in the whole string, and all other characters are left and right parentheses.

Now you are allowed to replace each ] with some number of ) characters. Find a way to obtain a valid parenthesis string after replacing all ] in SS.

Input Format

The first line contains two integers N,MN, M, representing the length of the string and the number of ].

The next several lines each contain at most 7272 characters, with a total of NN characters, representing the string SS.

Output Format

If there is no solution, output 0 and terminate the program.

If there is a solution, first output 1, then output MM lines. Each line contains one integer, representing how many ) characters the corresponding ] should be replaced with.

8 2
(((((])] 
1
3
1

Hint

Sample Explanation

For sample 11, after performing the replacements as in the input, the resulting SS is ((((())))), which is a valid parenthesis string.

Constraints

For 100%100\% of the testdata, 1N1071 \le N \le 10^7, 1M5×1061 \le M \le 5 \times 10^6, and MNM \le N.

This problem uses Special Judge.

Thanks to the SPJ provider

https://www.luogu.com.cn/user/60864

Notes

Translated from BalticOI 2005 Day1 B Magic Parenthesis.

Translated by ChatGPT 5