Editorial for Mock CCC '26 J4 - The Hidden Vault
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Subtask 1
With bits at most, we can try all possibilities. This can be implemented recursively, where at the
bit, we choose either to flip it or not. Then we check at the end if it is a valid bitstring, and take the minimum number of flips among all possibilities.
Time complexity:
Subtask 2
In this subtask, we only need at most 2 bit flips. We can loop all pairs of positions that might change , and there are
possibilities that can be set for the
and
positions, each being either
1 or 0. By trying each case, then checking if it is valid, we can see which case causes the least number of switches.
Time complexity:
Full Solution
We first observe that if we know any adjacent bits, then the remaining bits must be fixed.
Consider these cases:
11the next must be a
010the next must be a
101the next must be a
100the next must be a
0
From this, we can determine that there are total possibilities if we fix the first
bits. But upon construction, we notice that if we start with
11, 10, or 01 it may not be possible to have bits. During the construction, we end up with the same group of
bits being repeated (
101, 011, or 110). This means that must be a multiple of
in order to generate a series of bits that contain
11, 10, or 01. Otherwise, the only other option is to set them to be all 0.
To find the sequence of bits with the minimum number of flips, we can first check if is a multiple of
. If it is, then generate all
possibilities by fixing the first
bits, and then try them all. If
is not a multiple of
, then it must be all
0, so simply output the number of 1s.
Comments