Editorial for GlobeX Cup '18 J4 - Magical Functions
Submitting an official solution before solving the problem yourself is a bannable offence.
Authors:
,For the first subtask, we can simply loop through all values
For the second subtask, we can repeat subtask 1, except now that
For the remaining points, we can follow a direct implementation of the recursive function given to us in the problem statement. The statement gives the following:
The problem statement also states: we must output the answer in modulo
Using these rules, we can properly implement our recursive function without overflowing in any of our steps, obtaining the final 60 percent of points.
If you are attempting to pass in a language such as Python, you may want to implement memoization, storing previously met values in an array or map.
Comments
this is a scam you can't pass with python unless if you use memoization
I have updated the editorial, mentioning that memoization is recommended for slower languages. Thank you!
While I do think it would be beneficial for the author to suggest memoization for slower languages, the contest page (https://dmoj.ca/contest/globex18junior) only specifies problems are guaranteed to be solvable with C++, and not necessarily other languages. Hence, the author's intended solutions are only required to pass using C++.
Currently, only 1 C++ submission has TLEd, and that is because it is incorrect - not because the intended solution is too slow.