# BITOBYT — Editorial

Division 1

Division 2

None

### Explanation :

This is a simple simulation based problem. The most simply way is to just simulate the entire process written in the problem statement.

Before beginning our simulation, let’s make a small observation : One a single day, there can exist only a population of a single type. Initially, on day 0, there’s a single bit.

Now, exactly 2 days later the bit transforms into a nibble, exactly 8 days after that the nibble transforms into a byte and exactly 16 days after that, we have 2 bits, exactly 8 days after that we have 2 nibbles and so on.

So, without using any further ideas or any optimizations, we can just simulate this. Since the time limit is strict and we don’t want to take any chances, we can just precompute this information once initially for each possible n.

Let us maintain a table answer(i,j), 0 \le i \le 2, 0 \le j \le 1600, where answer(0,j) is population of bits on day j, answer(1,j) for population of nibbles on the j^{th} day and so on.

Now,let’s keep a variable curr, and add to it 2/8/16 as appropriate and update all days too, when the population doesn’t change. For example, let day curr have population of x number of bits. Then we need to add 2 to curr, and update , answer(0,j)=x, curr \le j < curr+2 . If the current day had a population of x nibbles, then we would add 8 to curr, and then update answer(1,j)=x, curr \le j < curr+8 .

Later, we can answer all queries in O(1)

Beyond this, you could just read the code to understand. Note that for larger days, answers can be really large, so don’t forget to use long numbers.

Time Complexity : O(maxn+T), where maxn=1600 .

Video solution in C++, Java and Python: https://youtu.be/EbgOk_IDl1I

1 Like

we can also use recursion and precomputation to solve this.

``````
[1]

[1]: https://www.codechef.com/viewsolution/20528341``````

Simplest Solution I think:

https://www.codechef.com/viewsolution/23765649

I used the same logic but didn’t get AC coz I didn’t put cin.tie(0).

I am getting ‘wrong answer’ with this code. But getting results normally.
Why codechef is not accepting?

https://www.codechef.com/viewsolution/24366772

a good solution for pythoners…easy to understand and short
https://www.codechef.com/viewsolution/20485053

Hello! I am new to codechef. My code seems to work fine with custom input but when I submit the code it is giving me wrong answer. Can anyone please help. This is my code:

for i in range(int(input().strip())):

``````total = int(input())
constraint = [2,8,16]
ans = [0,0,0]
i, num, x = 0, 1, 0

while i<total:
ans = [0,0,0]
ans[x] = num

if i%13 == 0 and i!=0:
num = num*2

i += constraint[x]
x = (x+1)%3

print(*ans)``````