Editorial for UTS Open '24 P4 - Political Espionage
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
The subtasks are meant to reward all suboptimal solutions and are not tied to any specific methods. Here are some common constructions:
Method 1: pairs
Set all
Then, set
Any pair
Thus, there are approximately
Method 2: pairs
Recurse Method 1 on both halves of the current range. The values you set for the numbers in the middle should decrease a sufficient amount (e.g. various functions work, but floor dividing by four is a simple example).
This method approaches
Intended Solution: pairs
Instead of building the array top down, we can build it bottom up. Define a recursive function that constructs a range of the array,
1) If L > R
, return.
2) If L == R
, set
is a valid pair now.
3) Otherwise, let M = (L + R) / 2
. Recurse on (L, M-1)
and (M+1, R)
.
- All pairs
satisfying or are valid now.
4) Set
is the minimum amount required to make all pairs satisfying valid.
Now, all pairs satisfying
We can call this recursive function on (1, N)
to receive full points. The maximum value that this construction uses when 7380642475
, around
Bonus
Python golf solution (87 bytes): https://dmoj.ca/src/6848763 (Credits to for the bulk of the logic + for optimizing it with walrus operator)
Comments