Your code is not working on ideone, can you fix it? http://ideone.com/1AnFUY I used your last submission in practice…
why im getting WA for this.
please help me with this
thanks in advance!!
http://www.codechef.com/viewsolution/3900904
try this test case <<>.The answer should be 0 , but ur code gives 2.
what do you mean by ad-hoc? ( one of prerequisites)
@rishab
why so coz <<> last two brackets are matching which is the case with the official test case of <>>> which gives 2 as output.
plz clarify it
you should output the length of the longest prefix
Can someone provide a solution for the same above problem if the word prefix was removed. I am getting considerable difficulties in doing this version. Eg. for <<<<<<<<> output:2 , for <><><<<<<<<<<> output:4.
My problem is that how do we track whether the new contiguous sub sequence extends the previous one or not. As in <<>><<>> output:8 but for <<>><<<>> output:4.
Please help!
you can solve the problem using divide and conquer approach with a segment tree. At each node of the segment tree, store the following 5 variables:
l -> the maximum positive sum from right end
li -> the index at which the maximum sum is achieved
r -> the minimum negative sum from left end
ri -> the index at which this minimum sum is achieved
b -> longest perfect bracket sequence in the interval
So, for a node N, the best can be calculated as the maximum of b values of the children, or taking the joint of the r value of the right child and l value of the left child. if mod of l of left child is less than mod of r of right child, then just find the index in the right child where the prefix sum is equal to -l. similar procedure if mod of r is smaller than mod of l. this is work in NlogN.
thanku got it
http://www.codechef.com/viewsolution/4150026 .WA checked with all cases discused above .Thanks in advance
For which test case am i getting WA ?. Please someone answer . my subbmission http://www.codechef.com/viewsolution/4167497 Thanks in advance
ad hoc means something that is not known in advance
What must be the output of ><<>> …Should it be 0 or 4 ??
ANswer for ><<>> should be 0
Why so ?? I can see that I have valid string of length 4 here
Why do we need to calculate “ans=max(ans,i+1)”? We can just write “ans=i+1” which will also work.
https://www.codechef.com/viewsolution/15906400
i dn know why i am getting WA please anyone suggest some edge cases .
Can anyone tell me what’s wrong with my code ?
Thanks !
Are these test cases correct ?
$ ./test < test.txt
6
4
0
0
2
6
4
$ cat test.txt
7
<><><><<<<>>>>
<<>>
><
><>
<><
<<>><<<<>>>>
><<>><<<>>>