Official

E - Sugoroku 4 Editorial by en_translator


The problem can be solved with a Dynamic Programming (DP) where \(\mathrm{dp}[i][j]\) is defined to be the probability of being in square \(j\) after spinning the roulette \(i\) times.

During the transitions, it is required to find \(\frac{1}{M}\) modulo \(998244353\); if you are using a slow language, computing it for every iteration costs too much, so you need to precalculate it.

With a precalculation, the number of states are \(\mathrm{O}(NK)\) and there are \(\mathrm{O}(M)\) transitions from each state, so the complexity is \(\mathrm{O}(NMK+ \log \mathrm{mod})\) (where \(\mathrm{mod}=998244353\)).

posted:
last update: