|
|
In my solution I had to solve following interesting subproblem. Given an array. There is somewhere a unique cutpoint in this array. We don't know where, but we can check, if x is a cutpoint in O(1). We have to find this cutpoint, split array in two parts and do the same recursively on both parts. We need to do it faster than in O(n^2). Solution: For a segment (l, r) check for cutpoints in following order: l, r, l+1, r-1, l+2, r-2, ... Let's construct the resulting sequence from N to 1 by keeping merged segments in stack. What is the condition for merging two segments? They are touching by one of the sides (r_1+1=l_2 or r_2+1=l_1). The last part of the solution is trivial (make a tree of merges, ...). Give me plz some tests. Please only good permutation :) 4 1 4 2 3 This test help me) (1, (2,3) * (4)) = (1,4,2,3) Wa 7 again :) 9 3 2 1 7 9 8 4 5 6 ((1)*(2)*(3),(4,5,6)*(7,(8)*(9))) For this input: 3 1 2 3 Is this output correct: (1,(2,3)) Why not? I think that it's correct. As an example of evaluating subexpression, (1, (2 * 3), 4) is shown. However, this is not a valid expression according to the grammar (* can only operate on sequences, not numbers). Which is correct? What do you mean by "..." in formal definition? Is it the same as <expression> ::= <sequence>{*<sequence>} and <sequence> ::= (<sequence element>{,<sequence element>} or smth else? |
|
|