Skip to content

Instantly share code, notes, and snippets.

@siburu
Created June 22, 2022 05:18
Show Gist options
  • Save siburu/b4d5ea9201ce8c65dedc483746029336 to your computer and use it in GitHub Desktop.
Save siburu/b4d5ea9201ce8c65dedc483746029336 to your computer and use it in GitHub Desktop.
def prob(a, n, t):
rest = t - a
if rest < 2:
return 0
if rest == 2:
return 4
if rest <= n + 1:
return rest + 1
if rest <= 2 * n:
return 2 * n - rest + 1
return 0
def answer(n, t):
sum = 0
for i in range(n):
a = i + 1
if a == 1:
sum += 2 * prob(a, n, t)
else:
sum += prob(a, n, t)
return sum / (n + 1) / (n + 1) / (n + 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment