Comments

Thank you! I totally missed this moment

It looks too complicated. My thinking was slightly different. Since A has to start and make the first turn, she doesn't have options. B decides in this case if he wants to hit or miss. And since B wants to maximize his score, the maximum what he could get is if he misses everything from A and then with A having 0, he would able to get y points (it's impossible to get more) and A will have x points. But also as they want to minimize their enemy's scope as a second parameter, there is no need for B to miss everything, he could hit the last ball from A (A will have 0 energy already) so she will waste this point and B will get it. And in this case A will have (x — 1) and B will have y points. There is no better option for B because if he hits any ball except the last one A should respond not to loose her point. In this case B won't have maximum possible score.

About centroids. Editorial says "If not, choose any other vertex on the path from x to y and the size of the largest connected component after cutting it will be smaller than x and y". Looks like this is impossible and centroids are always connected. If I am correct, please remove this confusing comment

0

Could someone help me please with Div2-D? Can't understand why my submission fails on test 6 https://mirror.codeforces.com/contest/1395/submission/89750243

Looks like editorial for C contains error "2. For the given sequence of length n calculate the resulting balance a and the minimum balance b." Should be "length m", not "n".

Could someone please help me to figure out what's wrong with my solution of C. Code. I try to use the same way as “Exponentiation by squaring”. If k is even I calculate number of variants for k / 2 recursively and then sum this value and this value multiplied by appropriate power of 2. Respectively, for odd k I calculate sum for single string and shifted (k — 1). This solution even passes several first tests but then fails with a wrong answer on a big test which isn't shown entirely. The question is if I have conceptual error in my solution and this idea doesn't work at all (why?) or I have bug in my implemetation