Editorial for LCC '23 Contest 1 S4 - Virus
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Subtask 1
The first subtask can be solved by simulating all instructions every day for days, and inserting numbers when needed. Note in the worst case, the array doubles in size each day.
Time Complexity:
Subtask 2
Notice it does not matter where the numbers in the array are located, so long as two adjacent values are kept track of. Thus, we can use a 2-D frequency array to store the frequency of every possible pair of adjacent values. Because , we only need an array of size to store every possible pair.
By simulating all instructions every day for days, each instruction x y
means we need to update every cell in our frequency table to , increase by , and increase by , where and is the value at cell prior to carrying out the instruction.
Note all instructions are carried out simultaneously, so each instruction should be handled independently (i.e. the frequency table should be updated at the end of every day, once all instructions have been carried out).
Time Compelexity:
Comments