公式

D - Triangle Card Game 解説 by evima


We will search exhaustively for the card \(a\) that Alice plays first. It is sufficient to determine if Bob can win against all possible opening moves.

Bob can win by playing a card \(b\) that satisfies the following condition:

  • There is no \(c\) in \(A\setminus \lbrace a\rbrace\) such that \(|a-b| < c < a+b\).

We will consider the cases depending on the relationship between \(a\) and \(b\).

If \(b < a\), it is not disadvantageous for Bob to play his smallest card, so we only need to check if Bob’s smallest card meets the condition.

If \(b \geq a\), we need to quickly determine if there is a \(b\) such that there is no \(c\) in \(A\setminus \lbrace a\rbrace\) satisfying \(b-a < c < b+a\). In other words, if we let \(\mathrm{dist}(b)\) be \(\min(|b-c|)\) over all \(c \in A \setminus \lbrace a\rbrace\), we need to find out if there is an element for which \(\mathrm{dist}(b)\) is at least \(a\).

Noting that \(\mathrm{dist}(b)\) is updated at most a constant number of times for each element, one can implement the above using a set.

Moreover, it is fine to omit the condition \(b \geq a\) and only check for Bob’s smallest card and \(\mathrm{dist}\) for all elements. This is because if \(b < a\), the condition that no element satisfies \(a-b < c < b+a\) is strictly more stringent than the condition that no element satisfies \(b-a < c < b+a\). This adjustment can make the implementation slightly lighter.

投稿日時:
最終更新: