Indigo Codes 2024
· 3 min · competitive programming , solutions
It’s been a while since I last posted. I had a few ideas for a post but never had the chance to write them.
Last Saturday, Indigo Codes 2024 happened.
I did not manage to take it due to a conflict, but the problems I managed to solve afterwards were quite interesting.
1. Special Mods#
Pretty standard prefix sum problem. Since , you can iterate over every range and see if the sum is equivalent to
2. Array Swapping#
Notice that the way a swap is defined means that you can only change a position to exactly one other position
Thus, you only need to check if each number is in either the -th position or the -th position.
If is in the -th position, add one to the answer, and swap the -th and -th position.
3. Beautiful Tree#
Greedily add edges.
4. William’s Garden 1#
Define as the number of ways modulo to restore a grid
The transition is as follows:
with and
This is correct because at each , we can either add a vertical swap, horizontal swaps, or a cycle of arbitrary length (counter)clockwise
Alternatively, one can notice that is the square of the -th fibonacci number (proof as to why on William’s Garden 2)
5. Favorite Sequences#
Define as the number of lovable sequences ending on the number after the -th number is considered modulo and as the sum of lovable sequences ending on the number after the -th number is considered modulo
The transitions are as follows:
At each , we only need to update one value of and , so the runtime is
6. Cifjump#
I don’t quite know how to utilize the small bound on , so I will describe a solution that works for larger
We can restate the problem as:
For each position , what is the minimum number of hops to move at least positions?
Using binary jumping, we can find the distance travelled in moves in . Naively binary searching leads to a time complexity of , which is too slow for
Notice that if we are doing a lot of recomputation every time we try a value of . If we allow the midpoint of the binary search to split the current interval into powers of 2, then we only need to do operations per check (This is also the idea behind bitwise binary search).
7. I Like My Trees Drippy#
I haven’t implemented this yet.
8. William’s Garden 2#
I also haven’t implement this yet, but the idea is really nice. Remember how the solution to the easy version was the square of the fibonacci numbers? This is because we can imagine swaps as two domino tilings, where the first one represents where the first tiling represents the way to move a pepper and the second represents the way to move a tomato.
Now comes the problem of calculating domino tilings. One can construct a linear recurrence dp for and use matrix exponentiation.
9. Work Shifts#
I haven’t read or implemented this yet.
10. Casino Dice Game#
Too hard.
Code#
Code for the first 6 problems can be found in this repository