Editorial for CIW '25 P2 - Chocolate Bar Partition 2
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Subtask 1
This subtask is designed to reward superexponential brute force solutions, such as recursive backtracking or enumerating all possible sequences of cuts.
Subtask 2
The key observation is the following: suppose the chocolate bar is partitioned into sub-bars. Then there exists an optimal solution that considers only one of the sub-bars.
Thus we have reduced the problem to an interval DP problem.
Define as the maximum tastiness Alice can achieve when considering only
.
We have the following recurrence for .
where
Here,
computes Bob's optimal response
to Alice cutting
into
and
if
he chooses to cut
.
In particular, if Bob cuts at index
,
then Alice will pick between the pieces that grants the maximum
tastiness between
.
Similarly, computes Bob's optimal response to Alice
if Bob chooses to cut
.
As Bob wants to minimize Alice's tastiness,
Bob will pick
.
The recurrence for thus takes the maximum over:
- cutting the chocolate at the index
that maximizes Bob's response
;
- cutting the chocolate and immediately eating the piece with the larger tastiness; and
- eating the whole piece;
respectively.
Naively memoizing and
will result in an
solution,
which is sufficient to pass subtask 2.
Subtask 3
To speed up the previous solution, we will define an auxiliary array
Note
can be computed in
, assuming the values of
it depends on already calculated.
To recover from
, note that every term we
are taking the minimum over in
is at least
.
Thus
.
Equality holds iff any term we take the minimum over equals
,
i.e. if
for any
.
Thus we obtain ,
and similarly,
,
which can be computed in
time.
Thus can be computed in
time.
Comments