An algorithm is proposed to optimize the performance of multiphase structures (composites) under elastodynamic loading conditions. The goal is to determine the distribution of material in the structure such that the time-averaged total stored energy of structure is minimized. A penalization strategy is suggested to avoid the checkerboard instability, simultaneously to generate near 0-1 topologies. As a result of this strategy, the solutions of presented algorithm are sufficiently smooth and possess the regularity of $H^1$ function space. A new way for the adjoint sensitivity analysis of the corresponding PDE-constrained optimization problem is presented. It is general and can be easily applied to a vide range of alternative problems. The success of introduced algorithm is studied by numerical experiments on a two-dimensional model problem for different numbers of phases ranging from 2 to 5. According to numerical results, the objective functional is reduced monotonically with iterations. It is reduced more than an order of magnitude after a few iterations of the presented algorithm. Moreover, the final topologies at the optimal solutions are near 0-1. The dynamic behavior of optimal designs are compared to initial ones to show the impact of optimization on the performance of structures.