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 satisfying
is valid.
Thus, there are approximately such pairs.
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 pairs, but may run into issues for larger
. Fine tuning the decreasing function may result in full points.
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, , ensuring that all pairs
satisfying
are valid. The intended solution uses the following method:
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 to
is the minimum amount required to make all pairs
satisfying
valid.
Now, all pairs satisfying are valid!
We can call this recursive function on (1, N)
to receive full points. The maximum value that this construction uses when is
7380642475
, around . This fits comfortably under the
limit.
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