ANKPAREN - Editorial

I am not the setter of the problem. :stuck_out_tongue: I’ll ask Ankit to reply.

1 Like

What causes NZEC in python I submitted a code in python , i tested in Codechef IDE which gave appropriate output when i submitted the same for the problem it gave me an NZEC

When i just wrote the same algo code in C++ 4.92 it gave me AC

Here is the link

Python : http://www.codechef.com/viewsolution/7261753

C++ : http://www.codechef.com/viewsolution/7262326

Can someone help me understand why this solution http://ideone.com/4PRXeG gave me WA. It works perfectly for the example given above and for any other test cases i could think off using the same logic as described above.

Can anybody please help me with my code that why it’s giving TLE .
Here’s a brief about what i have done.

CHECK 1 : if the input string is odd sized then if k>1 print -1 , else print string.

CHECK 2 : if the input string is irregular then if k>1 print -1 else print string.

CHECK 3 : i have converted the whole string from ‘(’ and ‘)’ to characters ‘a’ and ‘b’.
Then using the string concatenation operation and with the help of two temporary strings
generated all n-1 strings and hashed them into an map.
then finally checked if k>map.size() print -1
else find kth position in map and print that string after converting it back.

since i have used map . complexity would hardly go nlogn . and for 10^5 and at most 10 test cases . it would go 2 * (10^7) which goes strictly in 1 second. so why tle .?

here’s my


[1] . 
    


  [1]: http://ideone.com/l4J6rF

Can anyone tell me for which test case this solution http://www.codechef.com/viewsolution/7267574 is not working .?

can anyone pls tell why this solution is wrong…pls
http://www.codechef.com/viewsolution/7264909

Even i had same problem

Hi, I am glad you found the problem interesting.
However, the story behind this problem is not so interesting :P.

I proposed a version of this for cakewalk where you had to find only the lexicographically smallest. However, it seemed a little harder than a 1st problem should be yet, easier than 2nd problem :stuck_out_tongue:
So, I just modified it to ask for kth subsequence and tried to solve it myself. Needless to say, I was equally amazed upon finding such a beautiful pattern :smiley:

1 Like

That’s because adding strings is not the same thing as adding integers!

In line 59, you have a string final with 0 length. Then you reach line 63, where it has length n - 1. Notice that string concatenation takes time: O(number_of_characters_added). So, you have are doing n - 1 operations inside a loop that runs atleast n times. Thus, you have quadratic complexity and get TLE.