Bug in my solution of D?

Iterate over all points, if the answer for this point is yet to found then call function rec(Pi) from this point.

Description of rec(Pi) function:

Case 1: if Pi has any adjacent cell which is not in the input, set it as the answer for Pi and return.

Case 2: if all adjacent cells of Pi is present in the input, call rec function for the adjacent cells if there answers are yet to found. And then choose answer for Pi among the 4 adjacent cells answers(choose the one with shortest Manhattan distance).

code: here

In problem H, submitting even the editorial implementation gives TLE on test case 5.[Not even using "\n" instead of endl].

Hoping to see concise statements again and Ehab's X-OR won't be missed this time ig


Same. I just got 6 TLE with correct algorithm just for that and lost the points for C.


I got TLE in C just for taking inputs as double in my code. The same code when I just changed the input type from double to long long it got AC. Help!! Thanks in advance. Links to the TLE and AC code is given below and changes are also specified by comment.

There is another nice approach to Problem D using combinatorics.

steinum we can write (∑pik=0(ai+k)×(pik)×2pi−k) this part as this (3pi−1(3ai+1)). Is there any formula for this line you wrote??

Yes...But there is modular arithmetic..

Problem C was really awesome and the statements were also quite perfect...

If the string size 2e5 having all 1 in the string, then cnt =2e5. So after first mod operation X must become 0 to 2e5-2, X = the number of whose binary string is given. Let, it becomes X = 2e5-2 after first operation.Now for the second operation cnt must be less than 20 as log2(2e5-2)<20.Then we can check untill X becomes 0 as it will be a very few moves. And the first operation I tried to explain in my first comment....

Look after the first modulo operation x will be between 0 to cnt-1, cnt = number of 1. Then the binary representation will have 0-20 digits as log2(N) < 20. Then it's easy.

So we have to calculate the mod of first operation. Now the problem is X is huge. X can be written as X = sum of power of 2 from binary representation. And for every position in the binary string the number of 1 will be cnt+1 if S[i] = 0 or cnt-1 if S[i] = 1. So for this two we will calculate the module of X in O(n) operation.Let, after first operation X becomes a.

Now for pos 0 to n-1
if S[pos] = 0
   a = (X + pow(2, n-1-i))%(cnt+1)
   a = (X - pow(2, n-1-i))%(cnt-1)

This way we can handle the first operation. Another special case is cnt = 1, Then if S[pos] = 1, output will 0. Here is my Code

You don't had to ig... Brute force would suffice..

Thanks man. That means 1e18 format is double type.

In B:
For the statement: if(inp[i] <= 1e18/ans) I got WA. But when i wrote : if(inp[i] <= 1000000000000000000/ans) I got AC. Is there any differences between 1e18 and 1000000000000000000?? Otherwise what is the reason??

Can we get all the elements of the maximum subarray by kadane's algorithm??