Editorial for LCC '23 Contest 1 S4 - Virus


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: pingu

Subtask 1

The first subtask can be solved by simulating all M instructions every day for K days, and inserting numbers when needed. Note in the worst case, the array doubles in size each day.

Time Complexity: O(2^KNMK)

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 a_i, y \le 100, we only need an array of size 100 \times 100 to store every possible pair.

By simulating all M instructions every day for K days, each instruction x y means we need to update every cell in our frequency table (i, j) to 0, increase (i, y) by V, and increase (y, j) by V, where i+j=x and V is the value at cell (i, j) 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: O(NMK)


Comments

There are no comments at the moment.