Best to compare San Francisco with...Lausanne...or Chongqing (or any city with a bunch of hills that is fairly vertical).
How fast can you get from 4th & King to the SJC?
Nevertheless, comparing San Francisco to Lausanne is unfair. Lausanne provides better infrastructure for a smaller population.
Tokyo is in no way even close to flat. It has some flat areas (e.g. landfill in Tokyo bay), but there are huge numbers of very hilly areas as well (including many popular commercial hubs and densely populated areas in the city center). Not gentle hills in many cases either, but quite steep.
[... and if you go to the outskirts, there are actual mountains within the Tokyo city limits!]
One difference with with SF, of course, is that Tokyo roads don't form a rigid grid that ignores the topography....
> Japan cities spend a lot more money on infrastructure than even American cities
Tokyo mass transit is overwhelmingly private (owned, run, and financed), especially if you're talking about rail.
The Angel's Flight Train is still there.
The worlds oldest Freeway, the 110 goes through a valley.
The 5, 101, 10 and 60 wrap around all kinds of hills within a few miles of downtown LA.
So no, you don't need a flat grid to have great public transit.