Let p ≠ 3 be a prime, s , m be positive integers, and λ be a nonzero element of the finite field F p m . In [22] and [20] , when the generator polynomials have one or two different irreducible factors, the Hamming distances of λ -constacyclic codes of length 3 p s over F p m have been considered. In this paper, we obtain that the Hamming distances of the repeated-root λ -constacyclic codes of length l p s can be determined by the Hamming distances of the simple-root γ -constacyclic codes of length l , where l is a positive integer and λ = γ p s . Based on this result, the Hamming distances of the repeated-root λ -constacyclic codes of length 3 p s are given when the generator polynomials have three different irreducible factors. Hence, the Hamming distances of all such constacyclic codes are determined. As an application, we obtain all optimal λ -constacyclic codes of length 3 p s with respect to the Griesmer bound and the Singleton bound. Among others, several examples show that some of our codes have the best known parameters with respect to the code tables in [19]. [ABSTRACT FROM AUTHOR]