spoilers below
.
found a (potentially) (theoretically) optimal solution that is impossible to do in game because you cannot create turns that lead off of the screen. the impossible rail has been masterfully edited onto this image in red