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 f(L, R)
that constructs a range of the array, , ensuring that all pairs
satisfying
are valid. The intended solution uses the following method:
1) If , return.
2) If , set
is a valid pair now.
3) Otherwise, let . Recurse on
f(L, M-1)
and f(M+1, R)
.
- All pairs
satisfying
or
are valid now.
4) Set to
is the minimum amount required to make all pairs
satisfying
valid.
- This covers all the remaining cases.
Thus, after calling f(L, R)
, all pairs satisfying will be valid!
We can call this recursive function on f(1, N)
to receive full points. The maximum value that this construction uses when is
, which is 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