I attended a programming competition(it has ended now). I don't know why my solution is giving WA, I read the editorial, saw other people solution but unable to find a flaw in my solution. Obviously I am missing somewhere. Please help!
If the pattern is non regular, answer is the same. Otherwise answer would be of length 1 less than the original pattern. Now the 1st lexicographic-ally smallest pattern can be obtained by removing one of the ')' from the first chunk(continuous sequence) of ')' in original pattern. 2nd lexicographic-ally smallest pattern can be obtained by removing one of the ')' from the second(if any) chunk(continuous sequence) of ')' in original pattern.And so on. And then say there are 'x' chunks of ')'. And we need to find kth lexicographic-ally pattern such that (k>x). For this case we move from backward, so for (x+1)th smallest pattern we remove '(' from first chunk of '(' (moving backward to front), for (x+2)nd we remove '(' from second chunk, and so on. The same logic is explained in tutorial here.
See I know you will feel bad when I will tell you what is wrong in your answer.
But the only thing wrong is you using gets(). Its 2015 no one uses it. I changed that to a scanf statement i.e delete this part of your code and
write this instead.
And Your code will be accepted. Next time try avoiding use of gets. use scanf, cin, something else.