Editorial for An Animal Contest 4 P1 - Dasher's Digits
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Subtask 1
Due to the cyclic nature of the algorithm, it suffices to simulate the algorithm until we encounter the 0
at the front of the string, at which point it can be removed and the remaining characters outputted in order.
Time Complexity:
Subtask 2
If 0
that is removed last. This can be done by comparing 0
's appear in the input string. We can then remove the 0
that is removed first without any consequence.
From this point onwards, we can perform the same sort of simulation as outlined in Subtask 1.
Time Complexity:
Subtask 3
We still only care about the last 0
that is removed. We can find the index of this 0
by sorting the 0
's based on their 0
that is further back. Let's call the index of this last 0
0
characters in the input order before 0
characters in the input order after
A slightly faster solution involves maintaining
Time Complexity:
Comments