Editorial for DMOPC '20 Contest 6 P6 - Dumping Buckets
Submitting an official solution before solving the problem yourself is a bannable offence.
Authors:
,Subtask 1
Let
Note that when we pour bucket
That's all well and good if we know
Well if we take a full bucket, for instance, and pour it into a bucket with known volume, and then fill it and pour again, we have quite a bit of information. To be specific, if we take a bucket with known volume
Now, if
If
If
We can move left-to-right in our array and consider our
In order to start with a bucket of known volume, we empty out bucket
After our
Operations:
Full Solution
We are quite close to the full solution. Let's split up our pair processing part into two cases. In all cases, we have one bucket of unknown capacity and known volume and a full bucket (also of unknown capacity).
Case 1: the bucket of unknown capacity has zero volume
In this case, other than the very start, we can actually prove that we will always get here with another bucket
- dump
into - dump
into
If the second operation returns
Case 2: the bucket of unknown capacity has positive volume
In this case, we do the following, assuming
- dump
into - dump
into
Recall that we know
On the other hand, if the second operation does not overflow, we know that
Final Thoughts
The main observation here is that after processing a pair, we have a bucket of known volume, and a full bucket. If the bucket we don't know is empty, we have an extra bucket of known volume which is non-empty. Otherwise, if the bucket we don't know is non-empty, we can apply case 2, and reach one of our cases again.
To wrap this up, we can apply the
Operations:
P.S.: since a dump operation empties the source bucket, we don't need the empty operation.
P.S.S: We can actually save one operation in the second phase of the problem, since we have a bucket of known volume (alongside our last required bucket). Thanks to
for pointing this out.
Comments