FlyingElephant's blog

By FlyingElephant, history, 20 months ago, In English

I was solving three block palindrome (easy version). I attempted a top down solution which gives correct results but it is giving TLE on 2nd test case. I wonder if it is there any chance to solve it by using this approach or the constraint given are too tight to even try this out...

I looked at somebody else submissions but they use the same approach as the one suggested in the editorial.

Maybe converting this code to bottom up there is a chance to get accepted? Any help/hints/suggestion is appreaccited.

The idea behind my approach is just recursively going from left to right and considering all the possible cases such that the first element to be filled will be the one labelled with value v1, the second with value v2, the third with value v3. Having one of those values = 0 means the block considered in this case is empty (ie no value has been chosen at all, thisallows to check for candidates such that there is only one element occurring in the whole subseq). Finally in case at the end the seq is not a palindrome I prune the solution returning INT_MIN.

  • Vote: I like it
  • +2
  • Vote: I do not like it