  A search for direct top squark pair production resulting in events with
either a same-flavour opposite-sign dilepton pair with invariant mass
compatible with a $Z$ boson or a pair of jets compatible with a Standard Model
(SM) Higgs boson ($h$) is presented. Requirements on additional leptons, jets,
jets identified as originating from $b$-quarks, and missing transverse momentum
are imposed to target the other decay products of the top squark pair. The
analysis is performed using proton-proton collision data at $\sqrt{s}=13$ TeV
collected with the ATLAS detector at the LHC in 2015--2016, corresponding to an
integrated luminosity of 36.1 fb$^{-1}$. No excess is observed in the data with
respect to the SM predictions. The results are interpreted in two sets of
models. In the first set, direct production of pairs of lighter top squarks
($\tilde{t}_1$) with long decay chains involving $Z$ or Higgs bosons is
considered. The second set includes direct pair production of the heavier top
squark pairs ($\tilde{t}_2$) decaying via $\tilde{t}_2 \rightarrow Z
\tilde{t}_1 $ or $\tilde{t}_2 \rightarrow h \tilde{t}_1$. The results exclude
at 95\% confidence level $\tilde{t}_2$ and $\tilde{t}_1$ masses up to about 800
GeV, extending the exclusion region of supersymmetric parameter space covered
by previous LHC searches.
