20241210 ◎

…The translation from the in-memory representation to a byte sequence is called encoding (also known as serialization or marshallig)

JSON is one type of encoding format. For example, consider an API endpoint that reads data from a database and returns it in JSON format. In this case, the web server encodes (or serializes) the in-memory data into JSON before sending it to the client.

Although serialization is more commonly used in general, depending on the context, encoding might be more precise term.

2040B. Paint a Strip - 1000

def solve(n: int) -> int:
    count: int = 1
    ones: int = 1
    while ones < n:
        count += 1
        ones = (ones + 1) * 2

    return count


for _ in range(int(input())):
    n: int = int(input())
    print(solve(n))

Apparently, we must leverage the second type of operation as much as possible to minimize the count of the first type of operation.

To think about maximizing the effect of the second type of operation, doubling the painted area was the first thing that came to my brain.

1 1 1 1 0 0 0 0 0 0

operation 1 ->

1 1 1 1 0 0 0 0 0 1

operation 2 ->

1 1 1 1 1 1 1 1 1 1

Verbalizing the approach might have failed to convey my idea correctly. For competitive programming, I find it much easier to understand by reading code instead of its explanation.

Codeforces Round #992 (Div.2) Editorial

That… makese sense…

The operation 2 can be performed only between two groups of 1s, and when performed optimally filling 0s in-between, the count of the operation 2 does not exceed the count of the operation 1.

And, maximizing the number of elements the operation 2 can conver ends with the same solution as mine (or mine ended up with the optimal solution).


_ lb

increasing protein intake did not work out. I’ll consider a different approach


index 20241209 20241211