Almost optimal solution of initial-value problems by randomized and quantum algorithms