RANKS are based on time only, death count doesn't matter. Simply get as good of a time as you can. While selecting a level, it will give you a "time to beat" which is the time required to get the next highest rank. Getting 100% S-ranks is possible but its very very difficult !