Editorial for DMOPC '20 Contest 1 P4 - Victor Makes Bank


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: Kirito

Let ai be the number of baby crabs that are i months old, and let aT be the number of crabs that are adults. The transition from month k to month k+1 is given by:

[a0a1a2aT1aT][KaTa1a2aT2aT1+aT]

Subtask 1

For 20% of points, we can implement this transition directly with two nested for loops.

Time Complexity: O(NT)

Subtask 2

For the remaining 80% of points, we note the transformation is linear, and we can represent it with the matrix A:

A=[0000K00I01]

where I is the T×T identity matrix.

Then we can obtain the answer with

AN1[00C]

We can compute AN1 quickly using binary exponentiation.

Time Complexity: O(T3logN)


Comments

There are no comments at the moment.