Editorial for UTS Open '15 #4 - Subway


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.

Let f(i,j) be the chance of arriving on time if you're at station i with j minutes left.

Let ex(i,j) be the expected value of X if you're at station i with j minutes left.

Let g(i,j)=f(i,j)ex(i,j).

Let bmn be the value of bi corresponding to the nth edge leaving station m. xmn and ymn are defined similarly.

Let qi be the number of edges leaving station i.

Then:

f(i,j)=k=1qi1qi(z=jxikjyikf(bik,z)yikxik+1)g(i,j)=1f(i,j)k=1qi1qi(z=jxikjyikg(bik,z)yikxik+1)ex(i,j)=g(i,j)f(i,j)

The intuitive explanation of the above is that the expected value is the weighted average of the expected value of all possible next states, weighted according to (chance of reaching next state) × (chance of being on time from that state).

This leads immediately to an O((N2+M)T) solution, which can be improved to O((N+M)T) by storing the values of f and g with a prefix sum array.

Complexity: O((N+M)T)


Comments

There are no comments at the moment.