Official

F - Tournament Editorial by en_translator


The tournament in the Problem Statement can be considered as a perfect binary tree of depth \(N\).

Here, consider the following DP.

\(\mathrm{DP}[i][j]\coloneqq\): When Person \(j\) wins the match at Node \(i\) on the perfect binary tree, the maximum amount of money received by the loser of the matches at the nodes under Node \(i\).

First we estimate the number of states. There are \(\mathrm{O}(2^N)\) nodes, and \(\mathrm{O}(2^N)\) kinds of indices of \(j\), so there seems to be \(\mathrm{O}(2^{2N})\) states.

Actually, however, the nodes of each depth have a total of \(\mathrm{O}(2^N)\) kinds of indices of \(j\). Since the depth is \(O(N)\), there are \(\mathrm{O}(N2^{N})\) states, which is small enough to store in an array.

Now we consider the transition.

When updating the parent node by merging \(\mathrm{DP}[l][j]\) and \(\mathrm{DP}[r][k]\), it is difficult to exhaustively enumerate all pairs of \(j\) and \(k\). However, if the person on the \(l\) side will win, the maximum sum of the amount of money that the people in the \(r\) side does not depend on \(j\), so we can precalculate the maximum sum of the amount of money that the people in the \(r\) side so that we do not have to iterate over \(k\), thus optimize the transition. (Same applies when the person on the \(r\) side wins.)

This trick reduces the overall complexity of the transitions to \(\mathrm{O}(N2^{N})\), which is fast enough.

posted:
last update: