usaco

Clean implementations of solutions to USACO problems

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
def solve(u, d):
	print(u)
	a, b = map(int, input().split())
	if b == 0:
		return (a > 0) + 1
	if d == -1:
		d = 2 * solve(a, -1) + 1
	d = d - 1
	if d % 2 == 0:
		return (d >> 1) + solve(b, (d >> 1)) + 1
	else:
		return (d >> 1) + solve(a, (d >> 1) + 1) + 1

ans = solve(1, -1);
print("Answer", ans);