The ALMA Spectroscopic Survey in the HUDF : The Cosmic Dust and Gas Mass Densities in Galaxies up to z similar to 3